microsoft / mimalloc

mimalloc is a compact general purpose allocator with excellent performance.
MIT License
10.61k stars 866 forks source link

Fix int and long handling and the use of (u)intptr_t in _mi_vsnprintf #946

Closed ArtSin closed 3 weeks ago

ArtSin commented 1 month ago

va_arg with type long was used for both int and long arguments, but x86_64 Linux has 64-bit long, so passing an int argument to _mi_vsnprintf results in undefined behaviour. For example, here: https://github.com/microsoft/mimalloc/blob/db3d8485d2f45a6f179d784f602f9eff4f60795c/src/prim/unix/prim.c#L521-L524

intptr_t was used as the largest integer type, but on 32-bit systems it is 32-bit wide, while long long is 64-bit. intmax_t can be used instead.

ArtSin commented 1 month ago

@microsoft-github-policy-service agree company="ISP RAS"

ArtSin commented 1 month ago

@microsoft-github-policy-service rerun

daanx commented 3 weeks ago

Great -- thank you so much!