Skip to content

Commit 8fe23e6

Browse files
committed
just be normal; address PR feedback
1 parent 529ef31 commit 8fe23e6

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

src/cascadia/inc/cppwinrt_utils.h

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -315,14 +315,24 @@ try
315315
uintptr_t count{ 0 };
316316
double t[4]{ 0. }; // left, top, right, bottom
317317
wchar_t buf[17];
318+
std::wstring buf;
319+
auto& errnoRef = errno; // Nonzero cost, pay it once
318320
for (const auto& token : til::split_iterator{ padding, L',' })
319321
{
320-
const auto l{ std::min(token.size(), std::extent_v<decltype(buf)> - 1) };
321-
#pragma warning(suppress : 26459) // You called an STL function '...' with a raw pointer parameter at position '...' that may be unsafe ... (stl.1).
322-
std::copy_n(token.data(), l, &buf[0]); // the length of buf is controlled for above
323-
til::at(buf, l) = L'\0';
324-
til::at(t, count++) = std::wcstod(&buf[0], nullptr);
325-
if (count >= 4)
322+
buf.assign(token);
323+
// wcstod handles whitespace prefix (which is ignored) & stops the
324+
// scan when first char outside the range of radix is encountered.
325+
// We'll be permissive till the extent that stod function allows us to be by default
326+
// Ex. a value like 100.3#535w2 will be read as 100.3, but ;df25 will fail
327+
errnoRef = 0;
328+
wchar_t* end;
329+
const auto val{ std::wcstod(buf.c_str(), &end) };
330+
if (end != buf.c_str() && errnoRef != ERANGE)
331+
{
332+
til::at(t, count) = val;
333+
}
334+
335+
if (++count >= 4)
326336
{
327337
break;
328338
}

0 commit comments

Comments
 (0)