add run wrapper, move t_printf and t_status into separate translation unit
[libc-test.git] / src / functional / sscanf_long.c
blobc9208af0b2901fcdc28efac49b1cb36b014fc8c3
1 #include <stdlib.h>
2 #include <stdio.h>
3 #include <string.h>
4 #include <math.h>
5 #include <errno.h>
6 #include <sys/resource.h>
7 #include "test.h"
9 int main(void)
11 enum {n = 8*1024*1024};
12 char *s = malloc(n);
13 int i;
14 float f;
15 char c;
17 if (!s)
18 return t_error("out of memory");
19 t_setrlim(RLIMIT_STACK, 100*1024);
21 for (i = 0; i < n; i++) s[i] = '1';
22 s[n-3] = ' ';
23 s[n-1] = 0;
26 * stack overflow if scanf copies s on the stack (glibc)
27 * same issue with %d except then storing the conversion
28 * result is undefined behaviour
30 i = sscanf(s, "%f %c", &f, &c);
32 if (i != 2)
33 t_error("sscanf returned %d, want 2\n", i);
34 if (f != INFINITY)
35 t_error("sscanf(longnum, \"%%f\") read %f, want inf\n", f);
36 if (c != '1')
37 t_error("sscanf(\"1\", %%c) read '%c', want '1'\n", c);
38 free(s);
39 return t_status;