1570af302Sopenharmony_ci#include <stdlib.h>
2570af302Sopenharmony_ci#include <stdio.h>
3570af302Sopenharmony_ci#include <string.h>
4570af302Sopenharmony_ci#include <math.h>
5570af302Sopenharmony_ci#include <errno.h>
6570af302Sopenharmony_ci#include <sys/resource.h>
7570af302Sopenharmony_ci#include "test.h"
8570af302Sopenharmony_ci
9570af302Sopenharmony_ciint main(void)
10570af302Sopenharmony_ci{
11570af302Sopenharmony_ci	enum {n = 8*1024*1024};
12570af302Sopenharmony_ci	char *s = malloc(n);
13570af302Sopenharmony_ci	int i;
14570af302Sopenharmony_ci	float f;
15570af302Sopenharmony_ci	char c;
16570af302Sopenharmony_ci
17570af302Sopenharmony_ci	if (!s)
18570af302Sopenharmony_ci		return t_error("out of memory");
19570af302Sopenharmony_ci	t_setrlim(RLIMIT_STACK, 100*1024);
20570af302Sopenharmony_ci
21570af302Sopenharmony_ci	for (i = 0; i < n; i++) s[i] = '1';
22570af302Sopenharmony_ci	s[n-3] = ' ';
23570af302Sopenharmony_ci	s[n-1] = 0;
24570af302Sopenharmony_ci
25570af302Sopenharmony_ci	/*
26570af302Sopenharmony_ci	 * stack overflow if scanf copies s on the stack (glibc)
27570af302Sopenharmony_ci	 * same issue with %d except then storing the conversion
28570af302Sopenharmony_ci	 * result is undefined behaviour
29570af302Sopenharmony_ci	 */
30570af302Sopenharmony_ci	i = sscanf(s, "%f %c", &f, &c);
31570af302Sopenharmony_ci
32570af302Sopenharmony_ci	if (i != 2)
33570af302Sopenharmony_ci		t_error("sscanf returned %d, want 2\n", i);
34570af302Sopenharmony_ci	if (f != INFINITY)
35570af302Sopenharmony_ci		t_error("sscanf(longnum, \"%%f\") read %f, want inf\n", f);
36570af302Sopenharmony_ci	if (c != '1')
37570af302Sopenharmony_ci		t_error("sscanf(\"1\", %%c) read '%c', want '1'\n", c);
38570af302Sopenharmony_ci	free(s);
39570af302Sopenharmony_ci	return t_status;
40570af302Sopenharmony_ci}
41