Blame src/functional/sscanf_long.c

nsz 462b4f
#include <stdlib.h>
nsz 462b4f
#include <stdio.h>
nsz 462b4f
#include <string.h>
nsz 462b4f
#include <math.h>
nsz 462b4f
#include <errno.h>
nsz 462b4f
#include <sys/resource.h>
nsz 462b4f
#include "test.h"
nsz 462b4f
nsz 462b4f
int main(void)
nsz 462b4f
{
nsz 462b4f
	enum {n = 8*1024*1024};
nsz 462b4f
	char *s = malloc(n);
nsz 462b4f
	int i;
nsz 462b4f
	float f;
nsz 462b4f
	char c;
nsz 462b4f
nsz 462b4f
	if (!s)
Szabolcs Nagy cfa23c
		return t_error("out of memory");
Szabolcs Nagy 814c6f
	t_setrlim(RLIMIT_STACK, 100*1024);
nsz 462b4f
nsz 462b4f
	for (i = 0; i < n; i++) s[i] = '1';
nsz 462b4f
	s[n-3] = ' ';
nsz 462b4f
	s[n-1] = 0;
nsz 462b4f
nsz 462b4f
	/*
nsz 462b4f
	 * stack overflow if scanf copies s on the stack (glibc)
nsz 462b4f
	 * same issue with %d except then storing the conversion
nsz 462b4f
	 * result is undefined behaviour
nsz 462b4f
	 */
nsz 462b4f
	i = sscanf(s, "%f %c", &f, &c);
nsz 462b4f
nsz 462b4f
	if (i != 2)
Szabolcs Nagy cfa23c
		t_error("sscanf returned %d, want 2\n", i);
nsz 462b4f
	if (f != INFINITY)
Szabolcs Nagy cfa23c
		t_error("sscanf(longnum, \"%%f\") read %f, want inf\n", f);
nsz 462b4f
	if (c != '1')
Szabolcs Nagy cfa23c
		t_error("sscanf(\"1\", %%c) read '%c', want '1'\n", c);
nsz 462b4f
	free(s);
Szabolcs Nagy cfa23c
	return t_status;
nsz 462b4f
}