This source file includes following definitions.
- main
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 #include <config.h>
19
20 #include <string.h>
21
22 #include "signature.h"
23 SIGNATURE_CHECK (strnlen, size_t, (char const *, size_t));
24
25 #include <stdlib.h>
26
27 #include "zerosize-ptr.h"
28 #include "macros.h"
29
30 int
31 main (void)
32 {
33 size_t i;
34 char *page_boundary = (char *) zerosize_ptr ();
35 if (!page_boundary)
36 {
37 page_boundary = malloc (0x1000);
38 ASSERT (page_boundary);
39 page_boundary += 0x1000;
40 }
41
42
43 ASSERT (strnlen ("a", 0) == 0);
44 ASSERT (strnlen ("a", 1) == 1);
45 ASSERT (strnlen ("a", 2) == 1);
46 ASSERT (strnlen ("", 0x100000) == 0);
47
48
49 for (i = 0; i < 512; i++)
50 {
51 char *start = page_boundary - i;
52 size_t j = i;
53 memset (start, 'x', i);
54 do
55 {
56 if (i != j)
57 {
58 start[j] = 0;
59 ASSERT (strnlen (start, i + j) == j);
60 }
61 ASSERT (strnlen (start, i) == j);
62 ASSERT (strnlen (start, j) == j);
63 }
64 while (j--);
65 }
66
67 return 0;
68 }