refactor: remove unnecessary malloc result casts #1815

pull theStack wants to merge 1 commits into bitcoin-core:master from theStack:remove_malloc_result_casts changing 3 files +17 −17
  1. theStack commented at 3:14 pm on January 30, 2026: contributor

    While working on benchmark code for #1765, I noticed that in some instances we explicitly cast malloc results in the codebase. It seems that there is no good reason to do this in C, and it’s even considered bad practice, see e.g. https://stackoverflow.com/a/605858.

    This commit touches mostly test code, the only two functions used in production are secp256k1_context_{create,clone}. Instances were found manually via $ git grep "malloc(".

  2. real-or-random added the label tweak/refactor on Feb 2, 2026
  3. real-or-random added the label meta/development on Feb 2, 2026
  4. refactor: remove unnecessary `malloc` result casts
    It seems that there is no good reason to do this and it's even
    considered bad practice, see e.g. https://stackoverflow.com/a/605858
    
    This commit touches mostly test code, the only two functions used
    in production are `secp256k1_context_{create,clone}`.
    
    Instances were found manually via `$ git grep "malloc("`
    97b3c47849
  5. theStack force-pushed on Feb 2, 2026
  6. real-or-random approved
  7. real-or-random commented at 6:33 pm on February 3, 2026: contributor

    Weak Concept ACK && Code Review ACK https://github.com/bitcoin-core/secp256k1/pull/1815/changes/97b3c47849a7d124506a6208e1583ab74270188b

    I think that’s mostly a matter of style. But yeah, this results in less code without loss of readability, and it’s a bit more idiomatic, and that’s why I agree that the new style is better.

    IIUC the casts are necessary in C++, and this may be the primary reason why we these casts (e.g., I assume Pieter is more fluent in C++ than in C).

  8. w0xlt commented at 11:26 pm on February 3, 2026: none
    ACK 97b3c47849a7d124506a6208e1583ab74270188b
  9. real-or-random merged this on Feb 4, 2026
  10. real-or-random closed this on Feb 4, 2026

  11. theStack deleted the branch on Feb 4, 2026

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin-core/secp256k1. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-02-16 20:15 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me