File tree Expand file tree Collapse file tree 1 file changed +16
-6
lines changed Expand file tree Collapse file tree 1 file changed +16
-6
lines changed Original file line number Diff line number Diff line change @@ -315,14 +315,24 @@ try
315
315
uintptr_t count{ 0 };
316
316
double t[4 ]{ 0 . }; // left, top, right, bottom
317
317
wchar_t buf[17 ];
318
+ std::wstring buf;
319
+ auto & errnoRef = errno; // Nonzero cost, pay it once
318
320
for (const auto & token : til::split_iterator{ padding, L' ,' })
319
321
{
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 )
326
336
{
327
337
break ;
328
338
}
You can’t perform that action at this time.
0 commit comments