add an sscanf regression test
[libc-test.git] / src / regression / sscanf-eof.c
blobf67a378534353da76efb819e695cc446b3fbfe7e
1 // introduced by d6c855caa88ddb1ab6e24e23a14b1e7baf4ba9c7 2018-09-15
2 // sscanf may crash on short input
3 #include <stdio.h>
4 #include "test.h"
6 int main(void)
8 const char *s = "0";
9 const char *fmt = "%f%c";
10 float f = 1.0f;
11 char c = 'x';
12 int r = sscanf(s, fmt, &f, &c);
13 if (r != 1)
14 t_error("sscanf(\"%s\", \"%s\",..) returned %d, wanted 1\n", s, fmt, r);
15 if (f != 0.0f || c != 'x')
16 t_error("sscanf(\"%s\", \"%s\",..) assigned f=%f c='%c', wanted i=0 c='x'\n", s, fmt, f, c);
17 return t_status;