MDEV-31221 UBSAN runtime error: negation of -9223372036854775808 cannot be represented in type 'long long int' in my_strtoll10_utf32

The code in my_strtoll10_mb2 and my_strtoll10_utf32
could hit undefinite behavior by negation of LONGLONG_MIN.
Fixing to avoid this.

Also, fixing my_strtoll10() in the same style.
The previous reduction produced a redundant warning on
CAST(_latin1'-9223372036854775808' AS SIGNED)
This commit is contained in:
Alexander Barkov 2024-09-20 11:47:56 +04:00
commit 9ac8172ac3
8 changed files with 51 additions and 1 deletions

View file

@ -1011,6 +1011,8 @@ end4:
{
if (li > MAX_NEGATIVE_NUMBER)
goto overflow;
if (li == MAX_NEGATIVE_NUMBER) // Avoid undefinite behavior in negation
return LONGLONG_MIN;
return -((longlong) li);
}
return (longlong) li;
@ -2574,6 +2576,8 @@ end4:
{
if (li > MAX_NEGATIVE_NUMBER)
goto overflow;
if (li == MAX_NEGATIVE_NUMBER) // Avoid undefinite behavior in negation
return LONGLONG_MIN;
return -((longlong) li);
}
return (longlong) li;

View file

@ -241,8 +241,10 @@ end4:
*endptr= (char*) s;
if (negative)
{
if (li >= MAX_NEGATIVE_NUMBER) // Avoid undefined behavior
if (li > MAX_NEGATIVE_NUMBER)
goto overflow;
if (li == MAX_NEGATIVE_NUMBER) // Avoid undefined behavior
return LONGLONG_MIN;
return -((longlong) li);
}
return (longlong) li;