GrapheneOS / hardened_malloc

Hardened allocator designed for modern systems. It has integration into Android's Bionic libc and can be used externally with musl and glibc as a dynamic library for use on other Linux-based platforms. It will gain more portability / integration over time.
https://grapheneos.org/
MIT License
1.26k stars 96 forks source link

Add alloc_size attribute #177

Closed jvoisin closed 2 years ago

jvoisin commented 2 years ago

This should help a bit the compiler to emit better diagnostics and to improve the correctness of __builtin_object_size.

See https://clang.llvm.org/docs/AttributeReference.html#alloc-size

thestinger commented 2 years ago

@jvoisin I would prefer just adding the attribute directly rather than defining these 3 macros.

thestinger commented 2 years ago

If there was a need for portability, I think a single variadic macro would work. Could define an ALLOC_SIZE macro in util.h for that but it's not really worth it since there's no need for the portability.

thestinger commented 2 years ago

The existing macros there are for readability rather than portability. The only one where portability was needed was the OPTNONE one used for the tests to make them less likely to break due to testing things that are undefined behavior.

jvoisin commented 2 years ago

Sure, done.