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" 8 9int main(void) 10{ 11 enum {n = 8*1024*1024}; 12 char *s = malloc(n); 13 int i; 14 float f; 15 char c; 16 17 if (!s) 18 return t_error("out of memory"); 19 t_setrlim(RLIMIT_STACK, 100*1024); 20 21 for (i = 0; i < n; i++) s[i] = '1'; 22 s[n-3] = ' '; 23 s[n-1] = 0; 24 25 /* 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 29 */ 30 i = sscanf(s, "%f %c", &f, &c); 31 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; 40} 41