1#include <stdio.h>
2#include <stdlib.h>
3#include <libc-diag.h>
4
5int
6main(int arc, char *argv[])
7{
8 int res;
9 unsigned int val;
10
11 FILE *fp = fopen ("/dev/null", "r");
12
13 val = 0;
14 res = fscanf(stream: fp, format: "%n", &val);
15
16 printf(format: "Result of fscanf %%n = %d\n", res);
17 printf(format: "Scanned format = %d\n", val);
18
19 /* We're testing exactly the case the warning is for. */
20 DIAG_PUSH_NEEDS_COMMENT;
21 DIAG_IGNORE_NEEDS_COMMENT (4.9, "-Wformat-zero-length");
22
23 res = fscanf(stream: fp, format: "");
24
25 DIAG_POP_NEEDS_COMMENT;
26
27 printf(format: "Result of fscanf \"\" = %d\n", res);
28 if (res != 0)
29 abort ();
30
31 res = fscanf(stream: fp, format: "BLURB");
32 printf(format: "Result of fscanf \"BLURB\" = %d\n", res);
33 if (res >= 0)
34 abort ();
35
36 fclose (fp);
37
38 return 0;
39 return 0;
40}
41

source code of glibc/stdio-common/scanf4.c