Building a testdir on mingw with -D__USE_MINGW_ANSI_STDIO=0, I see these
test failures:

FAIL: test-c-strtof
===================

../../gltests/test-strtof.h:493: assertion 'errno == ERANGE' failed
FAIL test-c-strtof.exe (exit status: 3)

FAIL: test-strtof
=================

../../gltests/test-strtof.h:493: assertion 'errno == ERANGE' failed
FAIL test-strtof.exe (exit status: 3)

This patch fixes it.


2025-09-16  Bruno Haible  <[email protected]>

        strtof: Work around mingw bug with overflow.
        * lib/strtod.c (STRTOD): Recognize overflow.
        * modules/strtof (Depends-on): Add isinf.
        * modules/strtod (Depends-on): Likewise.
        * modules/strtold (Depends-on): Likewise.
        * doc/posix-functions/strtof.texi: Update mingw version.

diff --git a/doc/posix-functions/strtof.texi b/doc/posix-functions/strtof.texi
index f1675d8087..9caa74d58d 100644
--- a/doc/posix-functions/strtof.texi
+++ b/doc/posix-functions/strtof.texi
@@ -28,7 +28,7 @@
 
 @item
 This function fails to set @code{errno} upon overflow on some platforms:
-mingw 5.0.
+mingw 9.0.
 
 @item
 @c The term "underflow", as defined by ISO C23 ยง 7.12.1.(6), includes both
diff --git a/lib/strtod.c b/lib/strtod.c
index 1258753caf..73fe95ca03 100644
--- a/lib/strtod.c
+++ b/lib/strtod.c
@@ -492,6 +492,10 @@ STRTOD (const char *nptr, char **endptr)
                 }
               end = e;
             }
+          /* If "1e50" was converted to Inf (overflow), errno needs to be
+             set.  */
+          else if (isinf (num))
+            errno = ERANGE;
         }
 
       s = end;
diff --git a/modules/strtod b/modules/strtod
index 23ef6a5213..aaade58f7c 100644
--- a/modules/strtod
+++ b/modules/strtod
@@ -12,6 +12,7 @@ strtod-obsolete
 c-ctype         [test $HAVE_STRTOD = 0 || test $REPLACE_STRTOD = 1]
 math-h          [test $HAVE_STRTOD = 0 || test $REPLACE_STRTOD = 1]
 bool            [test $HAVE_STRTOD = 0 || test $REPLACE_STRTOD = 1]
+isinf           [test $HAVE_STRTOD = 0 || test $REPLACE_STRTOD = 1]
 
 configure.ac:
 gl_FUNC_STRTOD
diff --git a/modules/strtof b/modules/strtof
index df3d795100..306e77a040 100644
--- a/modules/strtof
+++ b/modules/strtof
@@ -12,6 +12,7 @@ stdlib-h
 c-ctype         [test $HAVE_STRTOF = 0 || test $REPLACE_STRTOF = 1]
 math-h          [test $HAVE_STRTOF = 0 || test $REPLACE_STRTOF = 1]
 bool            [test $HAVE_STRTOF = 0 || test $REPLACE_STRTOF = 1]
+isinf           [test $HAVE_STRTOF = 0 || test $REPLACE_STRTOF = 1]
 
 configure.ac:
 gl_FUNC_STRTOF
diff --git a/modules/strtold b/modules/strtold
index 4d8f6628b8..9cafe3f49a 100644
--- a/modules/strtold
+++ b/modules/strtold
@@ -13,6 +13,7 @@ stdlib-h
 c-ctype         [test $HAVE_STRTOLD = 0 || test $REPLACE_STRTOLD = 1]
 math-h          [test $HAVE_STRTOLD = 0 || test $REPLACE_STRTOLD = 1]
 bool            [test $HAVE_STRTOLD = 0 || test $REPLACE_STRTOLD = 1]
+isinf           [test $HAVE_STRTOLD = 0 || test $REPLACE_STRTOLD = 1]
 strtod          [{ test $HAVE_STRTOLD = 0 || test $REPLACE_STRTOLD = 1; } && 
test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1]
 
 configure.ac:




Reply via email to