Skip to content

Commit c897bd3

Browse files
listoutremiamichdolan
authored
Fix build and errno check on musl libc (#1678)
In the 'from_chars' function, it's first checked if errno != 0 and immediately returns with std::errc::result_out_of_range aka ERANGE. Please refer issue [1624] (#1624) The function 'strtol_l' is not available on non GLIBC systems hence on other libc use the alternative 'strtol' function. Signed-off-by: listout <[email protected]> Signed-off-by: listout <[email protected]> Co-authored-by: Rémi Achard <[email protected]> Co-authored-by: Michael Dolan <[email protected]>
1 parent 9a82ddb commit c897bd3

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/utils/NumberUtils.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ really_inline from_chars_result from_chars(const char *first, const char *last,
6868
tempval = ::strtod_l(first, &endptr, loc.local);
6969
#endif
7070

71-
if (errno != 0)
71+
if (errno != 0 && errno != EINVAL)
7272
{
7373
return {first + (endptr - first), std::errc::result_out_of_range};
7474
}
@@ -139,8 +139,10 @@ really_inline from_chars_result from_chars(const char *first, const char *last,
139139
long int
140140
#ifdef _WIN32
141141
tempval = _strtol_l(first, &endptr, 0, loc.local);
142-
#else
142+
#elif defined(__GLIBC__)
143143
tempval = ::strtol_l(first, &endptr, 0, loc.local);
144+
#else
145+
tempval = ::strtol(first, &endptr, 0);
144146
#endif
145147

146148
if (errno != 0)

0 commit comments

Comments
 (0)