From 07abfdb1a91b189eeec9ca09483994233722cf68 Mon Sep 17 00:00:00 2001 From: Nicolas Williams Date: Wed, 26 Oct 2022 01:54:19 -0500 Subject: [PATCH] roken: Fix UB --- lib/roken/snprintf.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/roken/snprintf.c b/lib/roken/snprintf.c index c8afedb26..928e4f4f3 100644 --- a/lib/roken/snprintf.c +++ b/lib/roken/snprintf.c @@ -449,13 +449,16 @@ xyzprintf (struct snprintf_state *state, const char *char_format, va_list ap) break; case 'd' : case 'i' : { - longest arg; - u_longest num; + int64_t arg; + uint64_t num; int minusp = 0; PARSE_INT_FORMAT(arg, ap, signed); - if (arg < 0) { + if (arg == INT64_MIN) { + minusp = 1; + num = (uint64_t)INT64_MAX + 1; + } else if (arg < 0) { minusp = 1; num = -arg; } else