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.
This commit is contained in:
Tobias Stoeckmann
2025-08-04 23:40:36 +02:00
parent 49bf72ac63
commit 14f4ca3287
+1 -1
View File
@@ -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