diff --git a/stl/src/xstoxflt.cpp b/stl/src/xstoxflt.cpp index d8b2c59057..82a2f8b409 100644 --- a/stl/src/xstoxflt.cpp +++ b/stl/src/xstoxflt.cpp @@ -22,12 +22,11 @@ _In_range_(0, maxsig) int _Stoxflt( char buf[_Maxsig + 1]; // worst case, with room for rounding digit int nsig = 0; // number of significant digits seen int seen = 0; // any valid field characters seen - int word = 0; // current long word to fill const char* pd; - static const char digits[] = "0123456789abcdefABCDEF"; - static const char vals[] = {// values of hex digits - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 10, 11, 12, 13, 14, 15}; + static constexpr char digits[] = "0123456789abcdefABCDEF"; // hex digits in both cases + static constexpr char vals[] = { + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 10, 11, 12, 13, 14, 15}; // values of hex digits maxsig *= _Ndig; // convert word count to digit count if (_Maxsig < maxsig) { @@ -63,11 +62,14 @@ _In_range_(0, maxsig) int _Stoxflt( } } - for (; (pd = static_cast(memchr(&digits[0], *s, 22))) != nullptr; ++s, seen = 1) { + while ((pd = static_cast(memchr(&digits[0], *s, 22))) != nullptr) { if (nsig <= maxsig) { // accumulate a fraction digit buf[nsig++] = vals[pd - digits]; --lo[0]; } + + ++s; + seen = 1; } if (maxsig < nsig) { // discard excess digit after rounding up @@ -88,6 +90,9 @@ _In_range_(0, maxsig) int _Stoxflt( } lo[0] <<= 2; // change hex exponent to binary exponent + + int word; // current long word to fill + if (seen) { // convert digit sequence to words int bufidx = 0; // next digit in buffer int wordidx = _Ndig - nsig % _Ndig; // next digit in word (% _Ndig) @@ -122,9 +127,7 @@ _In_range_(0, maxsig) int _Stoxflt( s = ssav; // roll back if incomplete exponent } } - } - - if (!seen) { + } else { word = 0; // return zero if bad parse } diff --git a/stl/src/xwstoxfl.cpp b/stl/src/xwstoxfl.cpp index 174ab1cf35..4c89411be8 100644 --- a/stl/src/xwstoxfl.cpp +++ b/stl/src/xwstoxfl.cpp @@ -22,14 +22,11 @@ _In_range_(0, maxsig) int _WStoxflt(const wchar_t* s0, const wchar_t* s, wchar_t char buf[_Maxsig + 1]; // worst case, with room for rounding digit int nsig = 0; // number of significant digits seen int seen = 0; // any valid field characters seen - int word = 0; // current long word to fill const wchar_t* pd; - static const wchar_t digits[] = {// hex digits in both cases - L'0', L'1', L'2', L'3', L'4', L'5', L'6', L'7', L'8', L'9', L'a', L'b', L'c', L'd', L'e', L'f', L'A', L'B', - L'C', L'D', L'E', L'F', L'\0'}; - static const char vals[] = {// values of hex digits - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 10, 11, 12, 13, 14, 15}; + static constexpr wchar_t digits[] = L"0123456789abcdefABCDEF"; // hex digits in both cases + static constexpr char vals[] = { + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 10, 11, 12, 13, 14, 15}; // values of hex digits maxsig *= _Ndig; // convert word count to digit count if (_Maxsig < maxsig) { @@ -55,7 +52,7 @@ _In_range_(0, maxsig) int _WStoxflt(const wchar_t* s0, const wchar_t* s, wchar_t seen = 1; } - if (*s == localeconv()->decimal_point[0]) { + if (*s == localeconv()->_W_decimal_point[0]) { ++s; } @@ -93,6 +90,9 @@ _In_range_(0, maxsig) int _WStoxflt(const wchar_t* s0, const wchar_t* s, wchar_t } lo[0] <<= 2; // change hex exponent to binary exponent + + int word; // current long word to fill + if (seen) { // convert digit sequence to words int bufidx = 0; // next digit in buffer int wordidx = _Ndig - nsig % _Ndig; // next digit in word (% _Ndig) @@ -127,9 +127,7 @@ _In_range_(0, maxsig) int _WStoxflt(const wchar_t* s0, const wchar_t* s, wchar_t s = ssav; // roll back if incomplete exponent } } - } - - if (!seen) { + } else { word = 0; // return zero if bad parse }