Describe the bug
Modifiers 'j' and 'z' do not work properly on some architecture, because the arguments have a size different from that inferred by the library, which results in wrong data being read from the varargs list.
case 'j': ... sizeof(intmax_t)
case 'z': ... sizeof(size_t)
Since intmax_t is not available for this library (see the discussion here: https://github.com/nothings/stb/pull/633), something else should be used, e.g. assume that it is always 8, or do this:
The proper handling was already suggested before (see #633 above), but since it was manually merged, also with the goal of minimizing dependencies, the wrong types were used.
Describe the bug Modifiers 'j' and 'z' do not work properly on some architecture, because the arguments have a size different from that inferred by the library, which results in wrong data being read from the varargs list.
To Reproduce
stb_sprintf(buff, "%ji %zi %ti", (intmax_t)-1, (ssize_t)2, (ptrdiff_t)-3);
taken from the test: https://github.com/nothings/stb/blob/beebb24b945efdea3b9bba23affb8eb3ba8982e7/tests/test_sprintf.c#L75 To be executed on a platform with:e.g. a 32-bit architecture like ARM Cortex-M
Fix This: https://github.com/nothings/stb/blob/beebb24b945efdea3b9bba23affb8eb3ba8982e7/stb_sprintf.h#L543-L551 should be changed to have:
Since
intmax_t
is not available for this library (see the discussion here: https://github.com/nothings/stb/pull/633), something else should be used, e.g. assume that it is always 8, or do this:Related https://github.com/nothings/stb/issues/632 https://github.com/nothings/stb/pull/633
The proper handling was already suggested before (see #633 above), but since it was manually merged, also with the goal of minimizing dependencies, the wrong types were used.