lib: cbprintf: improved %p specifier handling

This fixes an issue where the %p specifier always generated "(nil)"
on SPARC. The failing test cases were:
 tests/lib/sprintf/libraries.libc.sprintf
 tests/kernel/common/kernel.common.misra
 tests/kernel/common/kernel.common.tls
 tests/kernel/common/kernel.common

The exact logic behind the issue has not been fully analyzed, but
it can be observed that this commit eliminates one occurrence of
undefined behavior. (Only allowed to read the last union field written.)

Signed-off-by: Martin Åberg <martin.aberg@gaisler.com>
This commit is contained in:
Martin Åberg 2020-11-13 15:57:52 +01:00 committed by Andrew Boie
parent 73b7dde833
commit 9feb799762

View file

@ -1626,8 +1626,6 @@ int cbvprintf(cbprintf_cb out, void *ctx, const char *fp, va_list ap)
* has 0x prefix followed by significant address hex
* digits, no leading zeros.
*/
value.uint = (uintptr_t)value.ptr;
if (value.ptr != NULL) {
bps = encode_uint((uintptr_t)value.ptr, &conv,
buf, bpe);