1#include <locale.h>
2#include <stdio.h>
3#include <stdlib.h>
4#include <string.h>
5#include <wchar.h>
6
7int
8main (void)
9{
10 char *sp1, *sp2, *sp3, *sp4;
11 wchar_t *lsp1, *lsp2, *lsp3, *lsp4;
12 int result = 0;
13 char buf[2048+64];
14 size_t i;
15
16#define FAIL() \
17 do { \
18 result = 1; \
19 printf ("test at line %d failed\n", __LINE__); \
20 } while (0)
21
22 setlocale (LC_ALL, "de_DE.UTF-8");
23 if (sscanf ("A \xc3\x84-\t\t\xc3\x84-abcdefbcd\t\xc3\x84-B",
24 "A%ms%10ms%4m[bcd]%4mcB", &sp1, &sp2, &sp3, &sp4) != 4)
25 FAIL ();
26 else
27 {
28 if (strcmp (sp1, "\xc3\x84-") != 0)
29 FAIL ();
30 free (ptr: sp1);
31 if (strcmp (sp2, "\xc3\x84-abcdefb") != 0)
32 FAIL ();
33 free (ptr: sp2);
34 if (strcmp (sp3, "cd") != 0)
35 FAIL ();
36 free (ptr: sp3);
37 if (memcmp (sp4, "\t\xc3\x84-", 4) != 0)
38 FAIL ();
39 free (ptr: sp4);
40 }
41
42 if (sscanf ("A \xc3\x84-\t\t\xc3\x84-abcdefbcd\t\xc3\x84-BB",
43 "A%mS%10mls%4ml[bcd]%4mCB", &lsp1, &lsp2, &lsp3, &lsp4) != 4)
44 FAIL ();
45 else
46 {
47 if (wcscmp (s1: lsp1, s2: L"\xc4-") != 0)
48 FAIL ();
49 free (ptr: lsp1);
50 if (wcscmp (s1: lsp2, s2: L"\xc4-abcdefbc") != 0)
51 FAIL ();
52 free (ptr: lsp2);
53 if (wcscmp (s1: lsp3, s2: L"d") != 0)
54 FAIL ();
55 free (ptr: lsp3);
56 if (memcmp (lsp4, L"\t\xc4-B", 4 * sizeof (wchar_t)) != 0)
57 FAIL ();
58 free (ptr: lsp4);
59 }
60
61 memset (buf, '/', sizeof (buf));
62 buf[0] = '\t';
63 buf[1] = ' ';
64 buf[2] = 0xc3;
65 buf[3] = 0x84;
66 buf[2048] = 0xc3;
67 buf[2049] = 0x84;
68 buf[2058] = '\t';
69 buf[2059] = 'a';
70 buf[sizeof (buf) - 1] = '\0';
71 if (sscanf (buf, "%ms%mc", &sp1, &sp2) != 2)
72 FAIL ();
73 else
74 {
75 if (sp1[0] != '\xc3' || sp1[1] != '\x84'
76 || sp1[2046] != '\xc3' || sp1[2047] != '\x84'
77 || sp1[2056] != '\0')
78 FAIL ();
79 sp1[2046] = '/';
80 sp1[2047] = '/';
81 for (i = 2; i < 2056; i++)
82 if (sp1[i] != '/')
83 FAIL ();
84 free (ptr: sp1);
85 if (sp2[0] != '\t')
86 FAIL ();
87 free (ptr: sp2);
88 }
89 if (sscanf (buf, "%2048ms%mc", &sp3, &sp4) != 2)
90 FAIL ();
91 else
92 {
93 if (sp3[0] != '\xc3' || sp3[1] != '\x84'
94 || sp3[2046] != '\xc3' || sp3[2047] != '\x84'
95 || sp3[2048] != '\0')
96 FAIL ();
97 for (i = 2; i < 2046; i++)
98 if (sp3[i] != '/')
99 FAIL ();
100 free (ptr: sp3);
101 if (sp4[0] != '/')
102 FAIL ();
103 free (ptr: sp4);
104 }
105 if (sscanf (buf, "%4mc%1500m[dr/]%548m[abc/d]%3mc", &sp1, &sp2, &sp3, &sp4)
106 != 4)
107 FAIL ();
108 else
109 {
110 if (memcmp (sp1, "\t \xc3\x84", 4) != 0)
111 FAIL ();
112 free (ptr: sp1);
113 for (i = 0; i < 1500; i++)
114 if (sp2[i] != '/')
115 FAIL ();
116 if (sp2[1500] != '\0')
117 FAIL ();
118 free (ptr: sp2);
119 for (i = 0; i < 544; i++)
120 if (sp3[i] != '/')
121 FAIL ();
122 if (sp3[544] != '\0')
123 FAIL ();
124 free (ptr: sp3);
125 if (memcmp (sp4, "\xc3\x84/", 3) != 0)
126 FAIL ();
127 free (ptr: sp4);
128 }
129 if (sscanf (buf, "%mS%mC", &lsp1, &lsp2) != 2)
130 FAIL ();
131 else
132 {
133 if (lsp1[0] != L'\xc4' || lsp1[2045] != L'\xc4'
134 || lsp1[2054] != L'\0')
135 FAIL ();
136 lsp1[2045] = L'/';
137 for (i = 1; i < 2054; i++)
138 if (lsp1[i] != L'/')
139 FAIL ();
140 free (ptr: lsp1);
141 if (lsp2[0] != L'\t')
142 FAIL ();
143 free (ptr: lsp2);
144 }
145 if (sscanf (buf, "%2048mls%mlc", &lsp3, &lsp4) != 2)
146 FAIL ();
147 else
148 {
149 if (lsp3[0] != L'\xc4' || lsp3[2045] != L'\xc4'
150 || lsp3[2048] != L'\0')
151 FAIL ();
152 lsp3[2045] = L'/';
153 for (i = 1; i < 2048; i++)
154 if (lsp3[i] != L'/')
155 FAIL ();
156 free (ptr: lsp3);
157 if (lsp4[0] != L'/')
158 FAIL ();
159 free (ptr: lsp4);
160 }
161 if (sscanf (buf, "%4mC%1500ml[dr/]%548ml[abc/d]%3mlc",
162 &lsp1, &lsp2, &lsp3, &lsp4) != 4)
163 FAIL ();
164 else
165 {
166 if (memcmp (lsp1, L"\t \xc4/", 4 * sizeof (wchar_t)) != 0)
167 FAIL ();
168 free (ptr: lsp1);
169 for (i = 0; i < 1500; i++)
170 if (lsp2[i] != L'/')
171 FAIL ();
172 if (lsp2[1500] != L'\0')
173 FAIL ();
174 free (ptr: lsp2);
175 for (i = 0; i < 543; i++)
176 if (lsp3[i] != L'/')
177 FAIL ();
178 if (lsp3[543] != L'\0')
179 FAIL ();
180 free (ptr: lsp3);
181 if (memcmp (lsp4, L"\xc4//", 3 * sizeof (wchar_t)) != 0)
182 FAIL ();
183 free (ptr: lsp4);
184 }
185
186 return result;
187}
188

source code of glibc/stdio-common/scanf13.c