Fix bugs in parsing wxLongLong values starting with zeroes.
wxCRT_StrtoullBase(), used by wxString::To[U]LongLong(), didn't handle leading zeroes nor leading 0x correctly: it never auto-detected base 8; didn't ignore the leading 0 even if base 8 was specified explicitly; didn't recognize "0X" prefix at all (only "0x"). Fix all these bugs and add test cases for parsing numbers in other bases to the unit tests. Closes #14596. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@72408 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -975,23 +975,35 @@ wxCRT_StrtoullBase(const T* nptr, T** endptr, int base, T* sign)
|
||||
}
|
||||
}
|
||||
|
||||
// Starts with 0x?
|
||||
// Starts with octal or hexadecimal prefix?
|
||||
if ( i != end && *i == wxT('0') )
|
||||
{
|
||||
++i;
|
||||
if ( i != end )
|
||||
{
|
||||
if ( *i == wxT('x') && (base == 16 || base == 0) )
|
||||
if ( (*i == wxT('x')) || (*i == wxT('X')) )
|
||||
{
|
||||
base = 16;
|
||||
++i;
|
||||
// Hexadecimal prefix: use base 16 if auto-detecting.
|
||||
if ( base == 0 )
|
||||
base = 16;
|
||||
|
||||
// If we do use base 16, just skip "x" as well.
|
||||
if ( base == 16 )
|
||||
{
|
||||
++i;
|
||||
}
|
||||
else // Not using base 16
|
||||
{
|
||||
// Then it's an error.
|
||||
if ( endptr )
|
||||
*endptr = (T*) nptr;
|
||||
wxSET_ERRNO(EINVAL);
|
||||
return sum;
|
||||
}
|
||||
}
|
||||
else
|
||||
else if ( base == 0 )
|
||||
{
|
||||
if ( endptr )
|
||||
*endptr = (T*) nptr;
|
||||
wxSET_ERRNO(EINVAL);
|
||||
return sum;
|
||||
base = 8;
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user