build: fix compiler warnings in gnulib printf meson build checks

Otherwise, `CFLAGS='-Wall -Werror' meson build` fails detection with:

  ...
    if (sprintf (buf, "%.4000d %d", 1, 33, 44) < 4000 + 3)
      result |= 1;
    if (sprintf (buf, "%.4000f %d", 1.0, 33, 44) < 4000 + 5)
      result |= 2;
    if (sprintf (buf, "%.511f %d", 1.0, 33, 44) < 511 + 5
        || buf[0] != '1')
      result |= 4;
    if (sprintf (buf, "%.999f %d", 1.0, 33, 44) < 999 + 5
        || buf[0] != '1')
      result |= 4;
    return result;
  }

  -----------
  Command line: `cc /data/src/glib/build/meson-private/tmpu3dav6iy/testfile.c -o /data/src/glib/build/meson-private/tmpu3dav6iy/output.exe -Wall -Werror -D_FILE_OFFSET_BITS=64 -O0 -std=gnu99` -> 1
  stderr:
  /data/src/glib/build/meson-private/tmpu3dav6iy/testfile.c: In function 'main':
  /data/src/glib/build/meson-private/tmpu3dav6iy/testfile.c:12:21: error: too many arguments for format [-Werror=format-extra-args]
     12 |   if (sprintf (buf, "%.4000d %d", 1, 33, 44) < 4000 + 3)
        |                     ^~~~~~~~~~~~
  /data/src/glib/build/meson-private/tmpu3dav6iy/testfile.c:14:21: error: too many arguments for format [-Werror=format-extra-args]
     14 |   if (sprintf (buf, "%.4000f %d", 1.0, 33, 44) < 4000 + 5)
        |                     ^~~~~~~~~~~~
  /data/src/glib/build/meson-private/tmpu3dav6iy/testfile.c:16:21: error: too many arguments for format [-Werror=format-extra-args]
     16 |   if (sprintf (buf, "%.511f %d", 1.0, 33, 44) < 511 + 5
        |                     ^~~~~~~~~~~
  /data/src/glib/build/meson-private/tmpu3dav6iy/testfile.c:19:21: error: too many arguments for format [-Werror=format-extra-args]
     19 |   if (sprintf (buf, "%.999f %d", 1.0, 33, 44) < 999 + 5
        |                     ^~~~~~~~~~~
  cc1: all warnings being treated as errors
  -----------
  Could not compile test file /data/src/glib/build/meson-private/tmpu3dav6iy/testfile.c: 1
This commit is contained in:
Thomas Haller 2024-02-07 10:53:41 +01:00
parent a65fa9a33f
commit a91219f164
2 changed files with 9 additions and 9 deletions

View File

@ -16,27 +16,27 @@ static double zero = 0.0;
int main ()
{
int result = 0;
if (sprintf (buf, "%a %d", 3.1416015625, 33, 44, 55) < 0
if (sprintf (buf, "%a %d", 3.1416015625, 33) < 0
|| (strcmp (buf, "0x1.922p+1 33") != 0
&& strcmp (buf, "0x3.244p+0 33") != 0
&& strcmp (buf, "0x6.488p-1 33") != 0
&& strcmp (buf, "0xc.91p-2 33") != 0))
result |= 1;
if (sprintf (buf, "%A %d", -3.1416015625, 33, 44, 55) < 0
if (sprintf (buf, "%A %d", -3.1416015625, 33) < 0
|| (strcmp (buf, "-0X1.922P+1 33") != 0
&& strcmp (buf, "-0X3.244P+0 33") != 0
&& strcmp (buf, "-0X6.488P-1 33") != 0
&& strcmp (buf, "-0XC.91P-2 33") != 0))
result |= 2;
/* This catches a FreeBSD 6.1 bug: it doesn't round. */
if (sprintf (buf, "%.2a %d", 1.51, 33, 44, 55) < 0
if (sprintf (buf, "%.2a %d", 1.51, 33) < 0
|| (strcmp (buf, "0x1.83p+0 33") != 0
&& strcmp (buf, "0x3.05p-1 33") != 0
&& strcmp (buf, "0x6.0ap-2 33") != 0
&& strcmp (buf, "0xc.14p-3 33") != 0))
result |= 4;
/* This catches a Mac OS X 10.12.4 (Darwin 16.5) bug: it doesn't round. */
if (sprintf (buf, "%.0a %d", 1.51, 33, 44, 55) < 0
if (sprintf (buf, "%.0a %d", 1.51, 33) < 0
|| (strcmp (buf, "0x2p+0 33") != 0
&& strcmp (buf, "0x3p-1 33") != 0
&& strcmp (buf, "0x6p-2 33") != 0
@ -44,7 +44,7 @@ int main ()
result |= 4;
/* This catches a FreeBSD 6.1 bug. See
<https://lists.gnu.org/r/bug-gnulib/2007-04/msg00107.html> */
if (sprintf (buf, "%010a %d", 1.0 / zero, 33, 44, 55) < 0
if (sprintf (buf, "%010a %d", 1.0 / zero, 33) < 0
|| buf[0] == '0')
result |= 8;
/* This catches a Mac OS X 10.3.9 (Darwin 7.9) bug. */

View File

@ -23,14 +23,14 @@ int main ()
/* On BeOS, this would crash and show a dialog box. Avoid the crash. */
return 1;
#endif
if (sprintf (buf, "%.4000d %d", 1, 33, 44) < 4000 + 3)
if (sprintf (buf, "%.4000d %d", 1, 33) < 4000 + 3)
result |= 1;
if (sprintf (buf, "%.4000f %d", 1.0, 33, 44) < 4000 + 5)
if (sprintf (buf, "%.4000f %d", 1.0, 33) < 4000 + 5)
result |= 2;
if (sprintf (buf, "%.511f %d", 1.0, 33, 44) < 511 + 5
if (sprintf (buf, "%.511f %d", 1.0, 33) < 511 + 5
|| buf[0] != '1')
result |= 4;
if (sprintf (buf, "%.999f %d", 1.0, 33, 44) < 999 + 5
if (sprintf (buf, "%.999f %d", 1.0, 33) < 999 + 5
|| buf[0] != '1')
result |= 4;
return result;