Skip to content

Commit 2bc397b

Browse files
authored
Merge pull request #25292 from drodriguez/windows-fix-numeric-parsing
[windows] Fix usage of strtof/d/ld function usage.
2 parents a67ffad + 19a1e2c commit 2bc397b

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

stdlib/public/stubs/Stubs.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,12 @@ _swift_stdlib_strtoX_clocale_impl<float>(const char *str, float *result) {
393393
}
394394

395395
char *end;
396+
_set_errno(0);
396397
*result = _strtof_l(str, &end, getCLocale());
398+
if (*result == HUGE_VALF || *result == -HUGE_VALF || *result == 0.0 || *result == -0.0) {
399+
if (errno == ERANGE)
400+
end = nullptr;
401+
}
397402
return end;
398403
}
399404

@@ -406,7 +411,12 @@ _swift_stdlib_strtoX_clocale_impl<double>(const char *str, double *result) {
406411
}
407412

408413
char *end;
414+
_set_errno(0);
409415
*result = _strtod_l(str, &end, getCLocale());
416+
if (*result == HUGE_VAL || *result == -HUGE_VAL || *result == 0.0 || *result == -0.0) {
417+
if (errno == ERANGE)
418+
end = nullptr;
419+
}
410420
return end;
411421
}
412422

@@ -419,7 +429,12 @@ _swift_stdlib_strtoX_clocale_impl<long double>(const char *str, long double *res
419429
}
420430

421431
char *end;
432+
_set_errno(0);
422433
*result = _strtod_l(str, &end, getCLocale());
434+
if (*result == HUGE_VALL || *result == -HUGE_VALL || *result == 0.0 || *result == -0.0) {
435+
if (errno == ERANGE)
436+
end = nullptr;
437+
}
423438
return end;
424439
}
425440
#endif

0 commit comments

Comments
 (0)