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 if (sscanf (buf, "%ms%mc", &sp1, &sp2) != 2)
71 FAIL ();
72 else
73 {
74 if (sp1[0] != '\xc3' || sp1[1] != '\x84'
75 || sp1[2046] != '\xc3' || sp1[2047] != '\x84'
76 || sp1[2056] != '\0')
77 FAIL ();
78 sp1[2046] = '/';
79 sp1[2047] = '/';
80 for (i = 2; i < 2056; i++)
81 if (sp1[i] != '/')
82 FAIL ();
83 free (ptr: sp1);
84 if (sp2[0] != '\t')
85 FAIL ();
86 free (ptr: sp2);
87 }
88 if (sscanf (buf, "%2048ms%mc", &sp3, &sp4) != 2)
89 FAIL ();
90 else
91 {
92 if (sp3[0] != '\xc3' || sp3[1] != '\x84'
93 || sp3[2046] != '\xc3' || sp3[2047] != '\x84'
94 || sp3[2048] != '\0')
95 FAIL ();
96 for (i = 2; i < 2046; i++)
97 if (sp3[i] != '/')
98 FAIL ();
99 free (ptr: sp3);
100 if (sp4[0] != '/')
101 FAIL ();
102 free (ptr: sp4);
103 }
104 if (sscanf (buf, "%4mc%1500m[dr/]%548m[abc/d]%3mc", &sp1, &sp2, &sp3, &sp4)
105 != 4)
106 FAIL ();
107 else
108 {
109 if (memcmp (sp1, "\t \xc3\x84", 4) != 0)
110 FAIL ();
111 free (ptr: sp1);
112 for (i = 0; i < 1500; i++)
113 if (sp2[i] != '/')
114 FAIL ();
115 if (sp2[1500] != '\0')
116 FAIL ();
117 free (ptr: sp2);
118 for (i = 0; i < 544; i++)
119 if (sp3[i] != '/')
120 FAIL ();
121 if (sp3[544] != '\0')
122 FAIL ();
123 free (ptr: sp3);
124 if (memcmp (sp4, "\xc3\x84/", 3) != 0)
125 FAIL ();
126 free (ptr: sp4);
127 }
128 if (sscanf (buf, "%mS%mC", &lsp1, &lsp2) != 2)
129 FAIL ();
130 else
131 {
132 if (lsp1[0] != L'\xc4' || lsp1[2045] != L'\xc4'
133 || lsp1[2054] != L'\0')
134 FAIL ();
135 lsp1[2045] = L'/';
136 for (i = 1; i < 2054; i++)
137 if (lsp1[i] != L'/')
138 FAIL ();
139 free (ptr: lsp1);
140 if (lsp2[0] != L'\t')
141 FAIL ();
142 free (ptr: lsp2);
143 }
144 if (sscanf (buf, "%2048mls%mlc", &lsp3, &lsp4) != 2)
145 FAIL ();
146 else
147 {
148 if (lsp3[0] != L'\xc4' || lsp3[2045] != L'\xc4'
149 || lsp3[2048] != L'\0')
150 FAIL ();
151 lsp3[2045] = L'/';
152 for (i = 1; i < 2048; i++)
153 if (lsp3[i] != L'/')
154 FAIL ();
155 free (ptr: lsp3);
156 if (lsp4[0] != L'/')
157 FAIL ();
158 free (ptr: lsp4);
159 }
160 if (sscanf (buf, "%4mC%1500ml[dr/]%548ml[abc/d]%3mlc",
161 &lsp1, &lsp2, &lsp3, &lsp4) != 4)
162 FAIL ();
163 else
164 {
165 if (memcmp (lsp1, L"\t \xc4/", 4 * sizeof (wchar_t)) != 0)
166 FAIL ();
167 free (ptr: lsp1);
168 for (i = 0; i < 1500; i++)
169 if (lsp2[i] != L'/')
170 FAIL ();
171 if (lsp2[1500] != L'\0')
172 FAIL ();
173 free (ptr: lsp2);
174 for (i = 0; i < 543; i++)
175 if (lsp3[i] != L'/')
176 FAIL ();
177 if (lsp3[543] != L'\0')
178 FAIL ();
179 free (ptr: lsp3);
180 if (memcmp (lsp4, L"\xc4//", 3 * sizeof (wchar_t)) != 0)
181 FAIL ();
182 free (ptr: lsp4);
183 }
184
185 return result;
186}
187

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