Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compare the _W_decimal_point of the localeconv, not the decimal_point of said localeconv #3085

Merged
merged 9 commits into from
Sep 13, 2022
19 changes: 11 additions & 8 deletions stl/src/xstoxflt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -63,11 +62,14 @@ _In_range_(0, maxsig) int _Stoxflt(
}
}

for (; (pd = static_cast<const char*>(memchr(&digits[0], *s, 22))) != nullptr; ++s, seen = 1) {
while ((pd = static_cast<const char*>(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
Expand All @@ -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)
Expand Down Expand Up @@ -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
}

Expand Down
18 changes: 8 additions & 10 deletions stl/src/xwstoxfl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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]) {
AreaZR marked this conversation as resolved.
Show resolved Hide resolved
++s;
}

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
}

Expand Down