From 14f4ca328712a91a6246b5d11232f4edb7a15b90 Mon Sep 17 00:00:00 2001 From: Tobias Stoeckmann Date: Mon, 4 Aug 2025 23:40:36 +0200 Subject: [PATCH] gstrfuncs: Always treat G_MININT64 in g_ascii_strtoll If g_ascii_strtoll does not use strtoll_l, the result of g_parse_long_long could be G_MININT64 with gboolean negative set. In such a case, returning `- (gint64) result` would lead to an undefined behavior because -G_MININT64 would lead to an implicit integer overflow. Realistically though, this still leads to G_MININT64. Fixes test failure if compiled with ubsan on a platform without strtoll_l. --- glib/gstrfuncs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/glib/gstrfuncs.c b/glib/gstrfuncs.c index f0c305d30..7ac827619 100644 --- a/glib/gstrfuncs.c +++ b/glib/gstrfuncs.c @@ -1250,7 +1250,7 @@ g_ascii_strtoll (const gchar *nptr, return G_MAXINT64; } else if (negative) - return - (gint64) result; + return (result == (guint64) G_MININT64) ? G_MININT64 : -(gint64) result; else return (gint64) result; #endif