From: Bruno Haible Date: Tue, 22 May 2007 01:07:46 +0000 (+0000) Subject: Stricter check for printf result for NaN arguments. X-Git-Tag: cvs-readonly~353 X-Git-Url: http://erislabs.org.uk/gitweb/?a=commitdiff_plain;h=17ccaa9d86f36720593a6d75f277657177a6d8a9;p=gnulib.git Stricter check for printf result for NaN arguments. --- diff --git a/ChangeLog b/ChangeLog index 555ab9274..ef36f7454 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,19 @@ +2007-05-21 Bruno Haible + + * m4/printf.m4 (gl_PRINTF_INFINITE, gl_PRINTF_INFINITE_LONG_DOUBLE): + Check also the output for NaN arguments. When cross-compiling, guess + no on IRIX. + * lib/vasnprintf.c: Update comments. + * tests/test-vasnprintf-posix.c (strisnan): New function. + (test_function): Use it. + * tests/test-vasprintf-posix.c (strisnan): New function. + (test_function): Use it. + * tests/test-snprintf-posix.h (strisnan): New function. + (test_function): Use it. + * tests/test-sprintf-posix.h (strisnan): New function. + (test_function): Use it. + Reported by Eric Blake. + 2007-05-20 Bruno Haible * m4/frexpl.m4 (gl_FUNC_FREXPL_WORKS): Add test for large finite diff --git a/lib/vasnprintf.c b/lib/vasnprintf.c index bc5834fa9..c60888cde 100644 --- a/lib/vasnprintf.c +++ b/lib/vasnprintf.c @@ -1297,17 +1297,16 @@ VASNPRINTF (CHAR_T *resultbuf, size_t *lengthp, const CHAR_T *format, va_list ar # if NEED_PRINTF_INFINITE_DOUBLE || (a.arg[dp->arg_index].type == TYPE_DOUBLE /* The systems (mingw) which produce wrong output - for Inf and -Inf also do so for NaN and -0.0. - Therefore we treat these cases here as well. */ + for Inf, -Inf, and NaN also do so for -0.0. + Therefore we treat this case here as well. */ && is_infinite_or_zero (a.arg[dp->arg_index].a.a_double)) # endif # if NEED_PRINTF_LONG_DOUBLE || a.arg[dp->arg_index].type == TYPE_LONGDOUBLE # elif NEED_PRINTF_INFINITE_LONG_DOUBLE || (a.arg[dp->arg_index].type == TYPE_LONGDOUBLE - /* The systems which produce wrong output for Inf - and -Inf also do so for NaN. Therefore treat - this case here as well. */ + /* Some systems produce wrong output for Inf, + -Inf, and NaN. */ && is_infinitel (a.arg[dp->arg_index].a.a_longdouble)) # endif )) diff --git a/m4/printf.m4 b/m4/printf.m4 index fef64443a..a03f4a0b3 100644 --- a/m4/printf.m4 +++ b/m4/printf.m4 @@ -1,4 +1,4 @@ -# printf.m4 serial 12 +# printf.m4 serial 13 dnl Copyright (C) 2003, 2007 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -124,8 +124,8 @@ changequote([,])dnl ]) ]) -dnl Test whether the *printf family of functions supports infinite 'double' -dnl arguments in the %f, %e, %g directives. (ISO C99, POSIX:2001) +dnl Test whether the *printf family of functions supports infinite and NaN +dnl 'double' arguments in the %f, %e, %g directives. (ISO C99, POSIX:2001) dnl Result is gl_cv_func_printf_infinite. AC_DEFUN([gl_PRINTF_INFINITE], @@ -138,7 +138,26 @@ AC_DEFUN([gl_PRINTF_INFINITE], AC_TRY_RUN([ #include #include +static int +strisnan (const char *string, size_t start_index, size_t end_index) +{ + if (start_index < end_index) + { + if (string[start_index] == '-') + start_index++; + if (start_index + 3 <= end_index + && memcmp (string + start_index, "nan", 3) == 0) + { + start_index += 3; + if (start_index == end_index + || (string[start_index] == '(' && string[end_index - 1] == ')')) + return 1; + } + } + return 0; +} static char buf[100]; +static double zero = 0.0; int main () { if (sprintf (buf, "%f", 1.0 / 0.0) < 0 @@ -147,18 +166,27 @@ int main () if (sprintf (buf, "%f", -1.0 / 0.0) < 0 || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0)) return 1; + if (sprintf (buf, "%f", zero / zero) < 0 + || !strisnan (buf, 0, strlen (buf))) + return 1; if (sprintf (buf, "%e", 1.0 / 0.0) < 0 || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0)) return 1; if (sprintf (buf, "%e", -1.0 / 0.0) < 0 || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0)) return 1; + if (sprintf (buf, "%e", zero / zero) < 0 + || !strisnan (buf, 0, strlen (buf))) + return 1; if (sprintf (buf, "%g", 1.0 / 0.0) < 0 || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0)) return 1; if (sprintf (buf, "%g", -1.0 / 0.0) < 0 || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0)) return 1; + if (sprintf (buf, "%g", zero / zero) < 0 + || !strisnan (buf, 0, strlen (buf))) + return 1; return 0; }], [gl_cv_func_printf_infinite=yes], [gl_cv_func_printf_infinite=no], [ @@ -175,8 +203,6 @@ changequote(,)dnl # Guess yes on HP-UX >= 11. hpux[7-9]* | hpux10*) gl_cv_func_printf_infinite="guessing no";; hpux*) gl_cv_func_printf_infinite="guessing yes";; - # Guess yes on IRIX >= 6.5. - irix6.5) gl_cv_func_printf_infinite="guessing yes";; # Guess yes on NetBSD >= 3. netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*) gl_cv_func_printf_infinite="guessing no";; @@ -191,8 +217,8 @@ changequote([,])dnl ]) ]) -dnl Test whether the *printf family of functions supports infinite 'long double' -dnl arguments in the %f, %e, %g directives. (ISO C99, POSIX:2001) +dnl Test whether the *printf family of functions supports infinite and NaN +dnl 'long double' arguments in the %f, %e, %g directives. (ISO C99, POSIX:2001) dnl Result is gl_cv_func_printf_infinite_long_double. AC_DEFUN([gl_PRINTF_INFINITE_LONG_DOUBLE], @@ -208,7 +234,26 @@ AC_DEFUN([gl_PRINTF_INFINITE_LONG_DOUBLE], AC_TRY_RUN([ #include #include +static int +strisnan (const char *string, size_t start_index, size_t end_index) +{ + if (start_index < end_index) + { + if (string[start_index] == '-') + start_index++; + if (start_index + 3 <= end_index + && memcmp (string + start_index, "nan", 3) == 0) + { + start_index += 3; + if (start_index == end_index + || (string[start_index] == '(' && string[end_index - 1] == ')')) + return 1; + } + } + return 0; +} static char buf[100]; +static long double zeroL = 0.0L; int main () { if (sprintf (buf, "%Lf", 1.0L / 0.0L) < 0 @@ -217,18 +262,27 @@ int main () if (sprintf (buf, "%Lf", -1.0L / 0.0L) < 0 || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0)) return 1; + if (sprintf (buf, "%Lf", zeroL / zeroL) < 0 + || !strisnan (buf, 0, strlen (buf))) + return 1; if (sprintf (buf, "%Le", 1.0L / 0.0L) < 0 || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0)) return 1; if (sprintf (buf, "%Le", -1.0L / 0.0L) < 0 || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0)) return 1; + if (sprintf (buf, "%Le", zeroL / zeroL) < 0 + || !strisnan (buf, 0, strlen (buf))) + return 1; if (sprintf (buf, "%Lg", 1.0L / 0.0L) < 0 || (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0)) return 1; if (sprintf (buf, "%Lg", -1.0L / 0.0L) < 0 || (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0)) return 1; + if (sprintf (buf, "%Lg", zeroL / zeroL) < 0 + || !strisnan (buf, 0, strlen (buf))) + return 1; return 0; }], [gl_cv_func_printf_infinite_long_double=yes], @@ -247,8 +301,6 @@ changequote(,)dnl # Guess yes on HP-UX >= 11. hpux[7-9]* | hpux10*) gl_cv_func_printf_infinite_long_double="guessing no";; hpux*) gl_cv_func_printf_infinite_long_double="guessing yes";; - # Guess yes on IRIX >= 6.5. - irix6.5) gl_cv_func_printf_infinite_long_double="guessing yes";; # Guess yes on NetBSD >= 3. netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*) gl_cv_func_printf_infinite_long_double="guessing no";; @@ -895,7 +947,7 @@ dnl AIX 5.2 . . # # # . . . . # . . . . . dnl AIX 4.3.2, 5.1 # . # # # # . . . # . . . . . dnl HP-UX 11.31 . . . . # . . . . # . . # # . dnl HP-UX 10.20, 11.{00,11,23} # . . . # # . . . # . . # # # -dnl IRIX 6.5 # . . . # # . . . # . . # . . +dnl IRIX 6.5 # . # # # # . . . # . . # . . dnl OSF/1 5.1 # . # # # # . . . # . . # . # dnl OSF/1 4.0d # . # # # # . . . # # # # # # dnl NetBSD 4.0 . ? ? ? ? ? . . ? ? . . . ? ? diff --git a/tests/test-snprintf-posix.h b/tests/test-snprintf-posix.h index aec450ea5..ed03fb446 100644 --- a/tests/test-snprintf-posix.h +++ b/tests/test-snprintf-posix.h @@ -49,6 +49,27 @@ strmatch (const char *pattern, const char *string) return 1; } +/* Test whether string[start_index..end_index-1] is a valid textual + representation of NaN. */ +static int +strisnan (const char *string, size_t start_index, size_t end_index, int uppercase) +{ + if (start_index < end_index) + { + if (string[start_index] == '-') + start_index++; + if (start_index + 3 <= end_index + && memcmp (string + start_index, uppercase ? "NAN" : "nan", 3) == 0) + { + start_index += 3; + if (start_index == end_index + || (string[start_index] == '(' && string[end_index - 1] == ')')) + return 1; + } + } + return 0; +} + static void test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) { @@ -176,8 +197,7 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%a %d", NaN (), 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 - && (memcmp (result, "nan", 3) == 0 - || memcmp (result, "-nan", 4) == 0) + && strisnan (result, 0, strlen (result) - 3, 0) && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } @@ -376,8 +396,7 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) /* "0000000nan 33" is not a valid result; see */ ASSERT (strlen (result) == 20 + 3 - && (memcmp (result + strspn (result, " "), "nan", 3) == 0 - || memcmp (result + strspn (result, " "), "-nan", 4) == 0) + && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } @@ -442,8 +461,7 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%La %d", 0.0L / 0.0L, 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 - && (memcmp (result, "nan", 3) == 0 - || memcmp (result, "-nan", 4) == 0) + && strisnan (result, 0, strlen (result) - 3, 0) && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } @@ -643,8 +661,7 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) /* "0000000nan 33" is not a valid result; see */ ASSERT (strlen (result) == 20 + 3 - && (memcmp (result + strspn (result, " "), "nan", 3) == 0 - || memcmp (result + strspn (result, " "), "-nan", 4) == 0) + && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } @@ -804,8 +821,7 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%f %d", NaN (), 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 - && (memcmp (result, "nan", 3) == 0 - || memcmp (result, "-nan", 4) == 0) + && strisnan (result, 0, strlen (result) - 3, 0) && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } @@ -886,8 +902,7 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%020f %d", NaN (), 33, 44, 55); ASSERT (strlen (result) == 20 + 3 - && (memcmp (result + strspn (result, " "), "nan", 3) == 0 - || memcmp (result + strspn (result, " "), "-nan", 4) == 0) + && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } @@ -1054,8 +1069,7 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%Lf %d", zero / zero, 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 - && (memcmp (result, "nan", 3) == 0 - || memcmp (result, "-nan", 4) == 0) + && strisnan (result, 0, strlen (result) - 3, 0) && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } @@ -1137,8 +1151,7 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%020Lf %d", zero / zero, 33, 44, 55); ASSERT (strlen (result) == 20 + 3 - && (memcmp (result + strspn (result, " "), "nan", 3) == 0 - || memcmp (result + strspn (result, " "), "-nan", 4) == 0) + && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } @@ -1217,8 +1230,7 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%F %d", NaN (), 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 - && (memcmp (result, "NAN", 3) == 0 - || memcmp (result, "-NAN", 4) == 0) + && strisnan (result, 0, strlen (result) - 3, 1) && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } @@ -1313,8 +1325,7 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%LF %d", zero / zero, 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 - && (memcmp (result, "NAN", 3) == 0 - || memcmp (result, "-NAN", 4) == 0) + && strisnan (result, 0, strlen (result) - 3, 1) && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } @@ -1513,8 +1524,7 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%e %d", NaN (), 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 - && (memcmp (result, "nan", 3) == 0 - || memcmp (result, "-nan", 4) == 0) + && strisnan (result, 0, strlen (result) - 3, 0) && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } @@ -1605,8 +1615,7 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%020e %d", NaN (), 33, 44, 55); ASSERT (strlen (result) == 20 + 3 - && (memcmp (result + strspn (result, " "), "nan", 3) == 0 - || memcmp (result + strspn (result, " "), "-nan", 4) == 0) + && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } @@ -1774,8 +1783,7 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%Le %d", zero / zero, 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 - && (memcmp (result, "nan", 3) == 0 - || memcmp (result, "-nan", 4) == 0) + && strisnan (result, 0, strlen (result) - 3, 0) && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } @@ -1859,8 +1867,7 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%020Le %d", zero / zero, 33, 44, 55); ASSERT (strlen (result) == 20 + 3 - && (memcmp (result + strspn (result, " "), "nan", 3) == 0 - || memcmp (result + strspn (result, " "), "-nan", 4) == 0) + && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } @@ -2038,8 +2045,7 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%g %d", NaN (), 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 - && (memcmp (result, "nan", 3) == 0 - || memcmp (result, "-nan", 4) == 0) + && strisnan (result, 0, strlen (result) - 3, 0) && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } @@ -2123,8 +2129,7 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%020g %d", NaN (), 33, 44, 55); ASSERT (strlen (result) == 20 + 3 - && (memcmp (result + strspn (result, " "), "nan", 3) == 0 - || memcmp (result + strspn (result, " "), "-nan", 4) == 0) + && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } @@ -2292,8 +2297,7 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%Lg %d", zero / zero, 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 - && (memcmp (result, "nan", 3) == 0 - || memcmp (result, "-nan", 4) == 0) + && strisnan (result, 0, strlen (result) - 3, 0) && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } @@ -2377,8 +2381,7 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%020Lg %d", zero / zero, 33, 44, 55); ASSERT (strlen (result) == 20 + 3 - && (memcmp (result + strspn (result, " "), "nan", 3) == 0 - || memcmp (result + strspn (result, " "), "-nan", 4) == 0) + && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } diff --git a/tests/test-sprintf-posix.h b/tests/test-sprintf-posix.h index d1afd331a..6149dd78a 100644 --- a/tests/test-sprintf-posix.h +++ b/tests/test-sprintf-posix.h @@ -49,6 +49,27 @@ strmatch (const char *pattern, const char *string) return 1; } +/* Test whether string[start_index..end_index-1] is a valid textual + representation of NaN. */ +static int +strisnan (const char *string, size_t start_index, size_t end_index, int uppercase) +{ + if (start_index < end_index) + { + if (string[start_index] == '-') + start_index++; + if (start_index + 3 <= end_index + && memcmp (string + start_index, uppercase ? "NAN" : "nan", 3) == 0) + { + start_index += 3; + if (start_index == end_index + || (string[start_index] == '(' && string[end_index - 1] == ')')) + return 1; + } + } + return 0; +} + static void test_function (int (*my_sprintf) (char *, const char *, ...)) { @@ -162,8 +183,7 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%a %d", NaN (), 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 - && (memcmp (result, "nan", 3) == 0 - || memcmp (result, "-nan", 4) == 0) + && strisnan (result, 0, strlen (result) - 3, 0) && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } @@ -362,8 +382,7 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) /* "0000000nan 33" is not a valid result; see */ ASSERT (strlen (result) == 20 + 3 - && (memcmp (result + strspn (result, " "), "nan", 3) == 0 - || memcmp (result + strspn (result, " "), "-nan", 4) == 0) + && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } @@ -428,8 +447,7 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%La %d", 0.0L / 0.0L, 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 - && (memcmp (result, "nan", 3) == 0 - || memcmp (result, "-nan", 4) == 0) + && strisnan (result, 0, strlen (result) - 3, 0) && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } @@ -629,8 +647,7 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) /* "0000000nan 33" is not a valid result; see */ ASSERT (strlen (result) == 20 + 3 - && (memcmp (result + strspn (result, " "), "nan", 3) == 0 - || memcmp (result + strspn (result, " "), "-nan", 4) == 0) + && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } @@ -790,8 +807,7 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%f %d", NaN (), 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 - && (memcmp (result, "nan", 3) == 0 - || memcmp (result, "-nan", 4) == 0) + && strisnan (result, 0, strlen (result) - 3, 0) && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } @@ -866,8 +882,7 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%020f %d", NaN (), 33, 44, 55); ASSERT (strlen (result) == 20 + 3 - && (memcmp (result + strspn (result, " "), "nan", 3) == 0 - || memcmp (result + strspn (result, " "), "-nan", 4) == 0) + && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } @@ -1034,8 +1049,7 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%Lf %d", zero / zero, 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 - && (memcmp (result, "nan", 3) == 0 - || memcmp (result, "-nan", 4) == 0) + && strisnan (result, 0, strlen (result) - 3, 0) && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } @@ -1111,8 +1125,7 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%020Lf %d", zero / zero, 33, 44, 55); ASSERT (strlen (result) == 20 + 3 - && (memcmp (result + strspn (result, " "), "nan", 3) == 0 - || memcmp (result + strspn (result, " "), "-nan", 4) == 0) + && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } @@ -1191,8 +1204,7 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%F %d", NaN (), 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 - && (memcmp (result, "NAN", 3) == 0 - || memcmp (result, "-NAN", 4) == 0) + && strisnan (result, 0, strlen (result) - 3, 1) && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } @@ -1287,8 +1299,7 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%LF %d", zero / zero, 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 - && (memcmp (result, "NAN", 3) == 0 - || memcmp (result, "-NAN", 4) == 0) + && strisnan (result, 0, strlen (result) - 3, 1) && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } @@ -1487,8 +1498,7 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%e %d", NaN (), 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 - && (memcmp (result, "nan", 3) == 0 - || memcmp (result, "-nan", 4) == 0) + && strisnan (result, 0, strlen (result) - 3, 0) && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } @@ -1579,8 +1589,7 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%020e %d", NaN (), 33, 44, 55); ASSERT (strlen (result) == 20 + 3 - && (memcmp (result + strspn (result, " "), "nan", 3) == 0 - || memcmp (result + strspn (result, " "), "-nan", 4) == 0) + && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } @@ -1748,8 +1757,7 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%Le %d", zero / zero, 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 - && (memcmp (result, "nan", 3) == 0 - || memcmp (result, "-nan", 4) == 0) + && strisnan (result, 0, strlen (result) - 3, 0) && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } @@ -1833,8 +1841,7 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%020Le %d", zero / zero, 33, 44, 55); ASSERT (strlen (result) == 20 + 3 - && (memcmp (result + strspn (result, " "), "nan", 3) == 0 - || memcmp (result + strspn (result, " "), "-nan", 4) == 0) + && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } @@ -2012,8 +2019,7 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%g %d", NaN (), 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 - && (memcmp (result, "nan", 3) == 0 - || memcmp (result, "-nan", 4) == 0) + && strisnan (result, 0, strlen (result) - 3, 0) && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } @@ -2097,8 +2103,7 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%020g %d", NaN (), 33, 44, 55); ASSERT (strlen (result) == 20 + 3 - && (memcmp (result + strspn (result, " "), "nan", 3) == 0 - || memcmp (result + strspn (result, " "), "-nan", 4) == 0) + && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } @@ -2266,8 +2271,7 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%Lg %d", zero / zero, 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 - && (memcmp (result, "nan", 3) == 0 - || memcmp (result, "-nan", 4) == 0) + && strisnan (result, 0, strlen (result) - 3, 0) && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } @@ -2351,8 +2355,7 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%020Lg %d", zero / zero, 33, 44, 55); ASSERT (strlen (result) == 20 + 3 - && (memcmp (result + strspn (result, " "), "nan", 3) == 0 - || memcmp (result + strspn (result, " "), "-nan", 4) == 0) + && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } diff --git a/tests/test-vasnprintf-posix.c b/tests/test-vasnprintf-posix.c index db39fbe84..9dcf481cc 100644 --- a/tests/test-vasnprintf-posix.c +++ b/tests/test-vasnprintf-posix.c @@ -74,6 +74,27 @@ strmatch (const char *pattern, const char *string) return 1; } +/* Test whether string[start_index..end_index-1] is a valid textual + representation of NaN. */ +static int +strisnan (const char *string, size_t start_index, size_t end_index, int uppercase) +{ + if (start_index < end_index) + { + if (string[start_index] == '-') + start_index++; + if (start_index + 3 <= end_index + && memcmp (string + start_index, uppercase ? "NAN" : "nan", 3) == 0) + { + start_index += 3; + if (start_index == end_index + || (string[start_index] == '(' && string[end_index - 1] == ')')) + return 1; + } + } + return 0; +} + static void test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) { @@ -228,8 +249,7 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%a %d", NaN (), 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 - && (memcmp (result, "nan", 3) == 0 - || memcmp (result, "-nan", 4) == 0) + && strisnan (result, 0, strlen (result) - 3, 0) && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (length == strlen (result)); free (result); @@ -464,8 +484,7 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) /* "0000000nan 33" is not a valid result; see */ ASSERT (strlen (result) == 20 + 3 - && (memcmp (result + strspn (result, " "), "nan", 3) == 0 - || memcmp (result + strspn (result, " "), "-nan", 4) == 0) + && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (length == strlen (result)); free (result); @@ -544,8 +563,7 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%La %d", 0.0L / 0.0L, 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 - && (memcmp (result, "nan", 3) == 0 - || memcmp (result, "-nan", 4) == 0) + && strisnan (result, 0, strlen (result) - 3, 0) && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (length == strlen (result)); free (result); @@ -781,8 +799,7 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) /* "0000000nan 33" is not a valid result; see */ ASSERT (strlen (result) == 20 + 3 - && (memcmp (result + strspn (result, " "), "nan", 3) == 0 - || memcmp (result + strspn (result, " "), "-nan", 4) == 0) + && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (length == strlen (result)); free (result); @@ -960,8 +977,7 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%f %d", NaN (), 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 - && (memcmp (result, "nan", 3) == 0 - || memcmp (result, "-nan", 4) == 0) + && strisnan (result, 0, strlen (result) - 3, 0) && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (length == strlen (result)); free (result); @@ -1054,8 +1070,7 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%020f %d", NaN (), 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) == 20 + 3 - && (memcmp (result + strspn (result, " "), "nan", 3) == 0 - || memcmp (result + strspn (result, " "), "-nan", 4) == 0) + && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (length == strlen (result)); free (result); @@ -1242,8 +1257,7 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%Lf %d", zero / zero, 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 - && (memcmp (result, "nan", 3) == 0 - || memcmp (result, "-nan", 4) == 0) + && strisnan (result, 0, strlen (result) - 3, 0) && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (length == strlen (result)); free (result); @@ -1337,8 +1351,7 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%020Lf %d", zero / zero, 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) == 20 + 3 - && (memcmp (result + strspn (result, " "), "nan", 3) == 0 - || memcmp (result + strspn (result, " "), "-nan", 4) == 0) + && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (length == strlen (result)); free (result); @@ -1435,8 +1448,7 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%F %d", NaN (), 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 - && (memcmp (result, "NAN", 3) == 0 - || memcmp (result, "-NAN", 4) == 0) + && strisnan (result, 0, strlen (result) - 3, 1) && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (length == strlen (result)); free (result); @@ -1553,8 +1565,7 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%LF %d", zero / zero, 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 - && (memcmp (result, "NAN", 3) == 0 - || memcmp (result, "-NAN", 4) == 0) + && strisnan (result, 0, strlen (result) - 3, 1) && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (length == strlen (result)); free (result); @@ -1776,8 +1787,7 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%e %d", NaN (), 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 - && (memcmp (result, "nan", 3) == 0 - || memcmp (result, "-nan", 4) == 0) + && strisnan (result, 0, strlen (result) - 3, 0) && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (length == strlen (result)); free (result); @@ -1888,8 +1898,7 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%020e %d", NaN (), 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) == 20 + 3 - && (memcmp (result + strspn (result, " "), "nan", 3) == 0 - || memcmp (result + strspn (result, " "), "-nan", 4) == 0) + && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (length == strlen (result)); free (result); @@ -2077,8 +2086,7 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%Le %d", zero / zero, 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 - && (memcmp (result, "nan", 3) == 0 - || memcmp (result, "-nan", 4) == 0) + && strisnan (result, 0, strlen (result) - 3, 0) && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (length == strlen (result)); free (result); @@ -2182,8 +2190,7 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%020Le %d", zero / zero, 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) == 20 + 3 - && (memcmp (result + strspn (result, " "), "nan", 3) == 0 - || memcmp (result + strspn (result, " "), "-nan", 4) == 0) + && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (length == strlen (result)); free (result); @@ -2381,8 +2388,7 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%g %d", NaN (), 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 - && (memcmp (result, "nan", 3) == 0 - || memcmp (result, "-nan", 4) == 0) + && strisnan (result, 0, strlen (result) - 3, 0) && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (length == strlen (result)); free (result); @@ -2486,8 +2492,7 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%020g %d", NaN (), 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) == 20 + 3 - && (memcmp (result + strspn (result, " "), "nan", 3) == 0 - || memcmp (result + strspn (result, " "), "-nan", 4) == 0) + && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (length == strlen (result)); free (result); @@ -2675,8 +2680,7 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%Lg %d", zero / zero, 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 - && (memcmp (result, "nan", 3) == 0 - || memcmp (result, "-nan", 4) == 0) + && strisnan (result, 0, strlen (result) - 3, 0) && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (length == strlen (result)); free (result); @@ -2780,8 +2784,7 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%020Lg %d", zero / zero, 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) == 20 + 3 - && (memcmp (result + strspn (result, " "), "nan", 3) == 0 - || memcmp (result + strspn (result, " "), "-nan", 4) == 0) + && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (length == strlen (result)); free (result); diff --git a/tests/test-vasprintf-posix.c b/tests/test-vasprintf-posix.c index aa8a0bb29..51aebdfcc 100644 --- a/tests/test-vasprintf-posix.c +++ b/tests/test-vasprintf-posix.c @@ -74,6 +74,27 @@ strmatch (const char *pattern, const char *string) return 1; } +/* Test whether string[start_index..end_index-1] is a valid textual + representation of NaN. */ +static int +strisnan (const char *string, size_t start_index, size_t end_index, int uppercase) +{ + if (start_index < end_index) + { + if (string[start_index] == '-') + start_index++; + if (start_index + 3 <= end_index + && memcmp (string + start_index, uppercase ? "NAN" : "nan", 3) == 0) + { + start_index += 3; + if (start_index == end_index + || (string[start_index] == '(' && string[end_index - 1] == ')')) + return 1; + } + } + return 0; +} + static void test_function (int (*my_asprintf) (char **, const char *, ...)) { @@ -209,8 +230,7 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%a %d", NaN (), 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 - && (memcmp (result, "nan", 3) == 0 - || memcmp (result, "-nan", 4) == 0) + && strisnan (result, 0, strlen (result) - 3, 0) && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); free (result); @@ -445,8 +465,7 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) /* "0000000nan 33" is not a valid result; see */ ASSERT (strlen (result) == 20 + 3 - && (memcmp (result + strspn (result, " "), "nan", 3) == 0 - || memcmp (result + strspn (result, " "), "-nan", 4) == 0) + && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); free (result); @@ -525,8 +544,7 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%La %d", 0.0L / 0.0L, 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 - && (memcmp (result, "nan", 3) == 0 - || memcmp (result, "-nan", 4) == 0) + && strisnan (result, 0, strlen (result) - 3, 0) && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); free (result); @@ -762,8 +780,7 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) /* "0000000nan 33" is not a valid result; see */ ASSERT (strlen (result) == 20 + 3 - && (memcmp (result + strspn (result, " "), "nan", 3) == 0 - || memcmp (result + strspn (result, " "), "-nan", 4) == 0) + && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); free (result); @@ -941,8 +958,7 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%f %d", NaN (), 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 - && (memcmp (result, "nan", 3) == 0 - || memcmp (result, "-nan", 4) == 0) + && strisnan (result, 0, strlen (result) - 3, 0) && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); free (result); @@ -1035,8 +1051,7 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%020f %d", NaN (), 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) == 20 + 3 - && (memcmp (result + strspn (result, " "), "nan", 3) == 0 - || memcmp (result + strspn (result, " "), "-nan", 4) == 0) + && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); free (result); @@ -1223,8 +1238,7 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%Lf %d", zero / zero, 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 - && (memcmp (result, "nan", 3) == 0 - || memcmp (result, "-nan", 4) == 0) + && strisnan (result, 0, strlen (result) - 3, 0) && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); free (result); @@ -1318,8 +1332,7 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%020Lf %d", zero / zero, 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) == 20 + 3 - && (memcmp (result + strspn (result, " "), "nan", 3) == 0 - || memcmp (result + strspn (result, " "), "-nan", 4) == 0) + && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); free (result); @@ -1416,8 +1429,7 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%F %d", NaN (), 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 - && (memcmp (result, "NAN", 3) == 0 - || memcmp (result, "-NAN", 4) == 0) + && strisnan (result, 0, strlen (result) - 3, 1) && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); free (result); @@ -1534,8 +1546,7 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%LF %d", zero / zero, 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 - && (memcmp (result, "NAN", 3) == 0 - || memcmp (result, "-NAN", 4) == 0) + && strisnan (result, 0, strlen (result) - 3, 1) && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); free (result); @@ -1757,8 +1768,7 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%e %d", NaN (), 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 - && (memcmp (result, "nan", 3) == 0 - || memcmp (result, "-nan", 4) == 0) + && strisnan (result, 0, strlen (result) - 3, 0) && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); free (result); @@ -1869,8 +1879,7 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%020e %d", NaN (), 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) == 20 + 3 - && (memcmp (result + strspn (result, " "), "nan", 3) == 0 - || memcmp (result + strspn (result, " "), "-nan", 4) == 0) + && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); free (result); @@ -2058,8 +2067,7 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%Le %d", zero / zero, 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 - && (memcmp (result, "nan", 3) == 0 - || memcmp (result, "-nan", 4) == 0) + && strisnan (result, 0, strlen (result) - 3, 0) && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); free (result); @@ -2163,8 +2171,7 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%020Le %d", zero / zero, 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) == 20 + 3 - && (memcmp (result + strspn (result, " "), "nan", 3) == 0 - || memcmp (result + strspn (result, " "), "-nan", 4) == 0) + && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); free (result); @@ -2362,8 +2369,7 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%g %d", NaN (), 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 - && (memcmp (result, "nan", 3) == 0 - || memcmp (result, "-nan", 4) == 0) + && strisnan (result, 0, strlen (result) - 3, 0) && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); free (result); @@ -2467,8 +2473,7 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%020g %d", NaN (), 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) == 20 + 3 - && (memcmp (result + strspn (result, " "), "nan", 3) == 0 - || memcmp (result + strspn (result, " "), "-nan", 4) == 0) + && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); free (result); @@ -2656,8 +2661,7 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%Lg %d", zero / zero, 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 - && (memcmp (result, "nan", 3) == 0 - || memcmp (result, "-nan", 4) == 0) + && strisnan (result, 0, strlen (result) - 3, 0) && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); free (result); @@ -2761,8 +2765,7 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%020Lg %d", zero / zero, 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) == 20 + 3 - && (memcmp (result + strspn (result, " "), "nan", 3) == 0 - || memcmp (result + strspn (result, " "), "-nan", 4) == 0) + && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); free (result);