Fix parsing unsigned numbers in wxIntegerValidatorBase

Use wxNumberFormatter::FromString() overload taking wxULongLong_t to
allow parsing numbers greater than LLONG_MAX.
This commit is contained in:
Vadim Zeitlin
2021-02-21 19:05:13 +01:00
parent eb64202ad4
commit f1e6af089a
2 changed files with 23 additions and 3 deletions

View File

@@ -303,7 +303,7 @@ protected:
// Provide methods for wxNumValidator use. // Provide methods for wxNumValidator use.
wxString ToString(LongestValueType value) const; wxString ToString(LongestValueType value) const;
static bool FromString(const wxString& s, LongestValueType *value); bool FromString(const wxString& s, LongestValueType *value) const;
void DoSetMin(LongestValueType min) { m_min = min; } void DoSetMin(LongestValueType min) { m_min = min; }
LongestValueType DoGetMin() const { return m_min; } LongestValueType DoGetMin() const { return m_min; }

View File

@@ -234,9 +234,29 @@ wxString wxIntegerValidatorBase::ToString(LongestValueType value) const
} }
bool bool
wxIntegerValidatorBase::FromString(const wxString& s, LongestValueType *value) wxIntegerValidatorBase::FromString(const wxString& s,
LongestValueType *value) const
{ {
return wxNumberFormatter::FromString(s, value); if ( CanBeNegative() )
{
return wxNumberFormatter::FromString(s, value);
}
else
{
// Parse as unsigned to ensure we don't accept minus sign here.
#ifdef wxULongLong_t
wxULongLong_t uvalue;
#else
unsigned long uvalue;
#endif
if ( !wxNumberFormatter::FromString(s, &uvalue) )
return false;
// This cast is lossless.
*value = static_cast<LongestValueType>(uvalue);
return true;
}
} }
bool bool