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: contributor

    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
  12. Eunovo referenced this in commit a4d63b2089 on Feb 10, 2026
  13. fanquake referenced this in commit fa3704594c on Feb 19, 2026
  14. fanquake referenced this in commit 46ca85d851 on Feb 24, 2026
  15. fanquake referenced this in commit 9478a62d21 on Feb 25, 2026
  16. mllwchrry referenced this in commit 126501f58b on Mar 3, 2026
  17. fanquake referenced this in commit 0dab9edba4 on Mar 3, 2026
  18. fanquake referenced this in commit a50dbd2bcd on Mar 4, 2026
  19. real-or-random referenced this in commit 7a5f153d71 on Mar 4, 2026
  20. fanquake referenced this in commit ec7ea286b0 on Mar 10, 2026
  21. fanquake referenced this in commit 6458812af8 on Mar 17, 2026
  22. fanquake referenced this in commit 791949a724 on Mar 21, 2026
  23. fanquake referenced this in commit cffa9320f2 on Mar 23, 2026
  24. theStack referenced this in commit 994739fc33 on Mar 26, 2026
  25. fanquake referenced this in commit dfc5233b8c on Mar 27, 2026
  26. theStack referenced this in commit 0326234c51 on Apr 2, 2026
  27. fanquake referenced this in commit dfd54c959e on Apr 9, 2026
  28. vmta referenced this in commit 1ddc2f947f on Apr 26, 2026
  29. vmta referenced this in commit 56c40fe100 on Apr 27, 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-05-19 06:52 UTC