Skip to content

Commit 71ee767

Browse files
CV-Bowenpkarashchenko
authored andcommitted
vsprintf:fix bug when print int64 0x8000000000000000
stdio/lib_libvsprintf.c:1018:17: runtime error: negation of -9223372036854775808 cannot be represented in type 'long long int'; cast to an unsigned type to negate this value to itself #0 0x3326a86 in vsprintf_internal stdio/lib_libvsprintf.c:1018 #1 0x332926b in lib_vsprintf stdio/lib_libvsprintf.c:1363 #2 0x3777978 in vfprintf stdio/lib_vfprintf.c:52 apache#3 0x671b3a0 in printf stdio/lib_printf.c:44 apache#4 0x37abc0c in hello_main /data/project/code/vela-pt/apps/examples/hello/hello_main.c:38 apache#5 0x33201d3 in nxtask_startup sched/task_startup.c:70 apache#6 0x3208ecb in nxtask_start task/task_start.c:134 apache#7 0x3357a49 in pre_start sim/sim_initialstate.c:52 Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
1 parent bbf60ec commit 71ee767

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

libs/libc/stdio/lib_libvsprintf.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1018,7 +1018,11 @@ static int vsprintf_internal(FAR struct lib_outstream_s *stream,
10181018
flags &= ~(FL_NEGATIVE | FL_ALT);
10191019
if (x < 0)
10201020
{
1021-
x = -x;
1021+
#ifndef CONFIG_HAVE_LONG_LONG
1022+
x = -(unsigned long)x;
1023+
#else
1024+
x = -(unsigned long long)x;
1025+
#endif
10221026
flags |= FL_NEGATIVE;
10231027
}
10241028

0 commit comments

Comments
 (0)