File: bug23-3.c

package info (click to toggle)
glibc 2.24-11+deb9u4
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 225,852 kB
  • sloc: ansic: 996,505; asm: 261,827; sh: 10,484; makefile: 9,856; cpp: 4,169; python: 3,971; perl: 2,254; awk: 1,753; pascal: 1,521; yacc: 291; sed: 80
file content (50 lines) | stat: -rw-r--r-- 1,216 bytes parent folder | download | duplicates (18)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int
do_test (void)
{
  size_t instances = 16384;
#define X0 "\n%1$s\n" "%1$s" "%2$s" "%2$s" "%3$s" "%4$s" "%5$d" "%5$d"
  const char *item = "\na\nabbcd55";
#define X3 X0 X0 X0 X0 X0 X0 X0 X0
#define X6 X3 X3 X3 X3 X3 X3 X3 X3
#define X9 X6 X6 X6 X6 X6 X6 X6 X6
#define X12 X9 X9 X9 X9 X9 X9 X9 X9
#define X14 X12 X12 X12 X12
#define TRAILER "%%%%%%%%%%%%%%%%%%%%%%%%%%"
#define TRAILER2 TRAILER TRAILER
  size_t length = instances * strlen (item) + strlen (TRAILER) + 1;

  char *buf = malloc (length + 1);
  snprintf (buf, length + 1,
	    X14 TRAILER2 "\n",
	    "a", "b", "c", "d", 5);

  const char *p = buf;
  size_t i;
  for (i = 0; i < instances; ++i)
    {
      const char *expected;
      for (expected = item; *expected; ++expected)
	{
	  if (*p != *expected)
	    {
	      printf ("mismatch at offset %zu (%zu): expected %d, got %d\n",
		      (size_t) (p - buf), i, *expected & 0xFF, *p & 0xFF);
	      return 1;
	    }
	  ++p;
	}
    }
  if (strcmp (p, TRAILER "\n") != 0)
    {
      printf ("mismatch at trailer: [%s]\n", p);
      return 1;
    }
  free (buf);
  return 0;
}
#define TEST_FUNCTION do_test ()
#include "../test-skeleton.c"