usleep tests: Avoid failure due to known Cygwin 3.5.3 bug.
[gnulib.git] / tests / test-quotearg-simple.c
blobca6cd9df867bfbcec7f6439a81185c6954b08f99
1 /* Test of quotearg family of functions.
2 Copyright (C) 2008-2024 Free Software Foundation, Inc.
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3, or (at your option)
7 any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, see <https://www.gnu.org/licenses/>. */
17 /* Written by Eric Blake <ebb9@byu.net>, 2008. */
19 #include <config.h>
21 #include "quotearg.h"
23 #include <ctype.h>
24 #include <stdint.h>
25 #include <stdlib.h>
26 #include <string.h>
28 #include "localcharset.h"
29 #include "macros.h"
30 #include "zerosize-ptr.h"
32 #include "test-quotearg.h"
34 static struct result_groups results_g[] = {
35 /* literal_quoting_style */
36 { { "", "\0""1\0", 3, "simple", "\t'\t", " \t\n'\"\033?""?/\\", "a:b", "a\\b",
37 "a' b", LQ RQ, LQ RQ },
38 { "", "1", 1, "simple", "\t'\t", " \t\n'\"\033?""?/\\", "a:b", "a\\b",
39 "a' b", LQ RQ, LQ RQ },
40 { "", "1", 1, "simple", "\t'\t", " \t\n'\"\033?""?/\\", "a:b", "a\\b",
41 "a' b", LQ RQ, LQ RQ } },
43 /* shell_quoting_style */
44 { { "''", "\0""1\0", 3, "simple", "'\t'\\''\t'",
45 "' \t\n'\\''\"\033?""?/\\'", "a:b", "'a\\b'", "\"a' b\"",
46 LQ RQ, LQ RQ },
47 { "''", "1", 1, "simple", "'\t'\\''\t'",
48 "' \t\n'\\''\"\033?""?/\\'", "a:b", "'a\\b'", "\"a' b\"",
49 LQ RQ, LQ RQ },
50 { "''", "1", 1, "simple", "'\t'\\''\t'",
51 "' \t\n'\\''\"\033?""?/\\'", "'a:b'", "'a\\b'", "\"a' b\"",
52 LQ RQ, LQ RQ } },
54 /* shell_always_quoting_style */
55 { { "''", "'\0""1\0'", 5, "'simple'", "'\t'\\''\t'",
56 "' \t\n'\\''\"\033?""?/\\'", "'a:b'", "'a\\b'", "\"a' b\"",
57 "'" LQ RQ "'", "'" LQ RQ "'" },
58 { "''", "'1'", 3, "'simple'", "'\t'\\''\t'",
59 "' \t\n'\\''\"\033?""?/\\'", "'a:b'", "'a\\b'", "\"a' b\"",
60 "'" LQ RQ "'", "'" LQ RQ "'" },
61 { "''", "'1'", 3, "'simple'", "'\t'\\''\t'",
62 "' \t\n'\\''\"\033?""?/\\'", "'a:b'", "'a\\b'", "\"a' b\"",
63 "'" LQ RQ "'", "'" LQ RQ "'" } },
65 /* shell_escape_quoting_style */
66 { { "''", "''$'\\0''1'$'\\0'", 15, "simple", "''$'\\t'\\'''$'\\t'",
67 "' '$'\\t\\n'\\''\"'$'\\033''?""?/\\'", "a:b",
68 "'a\\b'", "\"a' b\"", "''$'" LQ_ENC RQ_ENC "'", LQ RQ },
69 { "''", "''$'\\0''1'$'\\0'", 15, "simple", "''$'\\t'\\'''$'\\t'",
70 "' '$'\\t\\n'\\''\"'$'\\033''?""?/\\'", "a:b",
71 "'a\\b'", "\"a' b\"", "''$'" LQ_ENC RQ_ENC "'", LQ RQ },
72 { "''", "''$'\\0''1'$'\\0'", 15, "simple", "''$'\\t'\\'''$'\\t'",
73 "' '$'\\t\\n'\\''\"'$'\\033''?""?/\\'", "'a:b'",
74 "'a\\b'", "\"a' b\"", "''$'" LQ_ENC RQ_ENC "'", LQ RQ } },
76 /* shell_escape_always_quoting_style */
77 { { "''", "''$'\\0''1'$'\\0'", 15, "'simple'", "''$'\\t'\\'''$'\\t'",
78 "' '$'\\t\\n'\\''\"'$'\\033''?""?/\\'", "'a:b'",
79 "'a\\b'", "\"a' b\"", "''$'" LQ_ENC RQ_ENC "'", "'" LQ RQ "'" },
80 { "''", "''$'\\0''1'$'\\0'", 15, "'simple'", "''$'\\t'\\'''$'\\t'",
81 "' '$'\\t\\n'\\''\"'$'\\033''?""?/\\'", "'a:b'",
82 "'a\\b'", "\"a' b\"", "''$'" LQ_ENC RQ_ENC "'", "'" LQ RQ "'" },
83 { "''", "''$'\\0''1'$'\\0'", 15, "'simple'", "''$'\\t'\\'''$'\\t'",
84 "' '$'\\t\\n'\\''\"'$'\\033''?""?/\\'", "'a:b'",
85 "'a\\b'", "\"a' b\"", "''$'" LQ_ENC RQ_ENC "'", "'" LQ RQ "'" } },
87 /* c_quoting_style */
88 { { "\"\"", "\"\\0001\\0\"", 9, "\"simple\"", "\"\\t'\\t\"",
89 "\" \\t\\n'\\\"\\033?""?/\\\\\"", "\"a:b\"", "\"a\\\\b\"",
90 "\"a' b\"", "\"" LQ_ENC RQ_ENC "\"", "\"" LQ RQ "\"" },
91 { "\"\"", "\"\\0001\\0\"", 9, "\"simple\"", "\"\\t'\\t\"",
92 "\" \\t\\n'\\\"\\033?""?/\\\\\"", "\"a:b\"", "\"a\\\\b\"",
93 "\"a' b\"", "\"" LQ_ENC RQ_ENC "\"", "\"" LQ RQ "\"" },
94 { "\"\"", "\"\\0001\\0\"", 9, "\"simple\"", "\"\\t'\\t\"",
95 "\" \\t\\n'\\\"\\033?""?/\\\\\"", "\"a\\:b\"", "\"a\\\\b\"",
96 "\"a' b\"", "\"" LQ_ENC RQ_ENC "\"", "\"" LQ RQ "\"" } },
98 /* c_maybe_quoting_style */
99 { { "", "\"\\0001\\0\"", 9, "simple", "\"\\t'\\t\"",
100 "\" \\t\\n'\\\"\\033?""?/\\\\\"", "a:b", "a\\b", "a' b",
101 "\"" LQ_ENC RQ_ENC "\"", LQ RQ },
102 { "", "\"\\0001\\0\"", 9, "simple", "\"\\t'\\t\"",
103 "\" \\t\\n'\\\"\\033?""?/\\\\\"", "a:b", "a\\b", "a' b",
104 "\"" LQ_ENC RQ_ENC "\"", LQ RQ },
105 { "", "\"\\0001\\0\"", 9, "simple", "\"\\t'\\t\"",
106 "\" \\t\\n'\\\"\\033?""?/\\\\\"", "\"a:b\"", "a\\b", "a' b",
107 "\"" LQ_ENC RQ_ENC "\"", LQ RQ } },
109 /* escape_quoting_style */
110 { { "", "\\0001\\0", 7, "simple", "\\t'\\t", " \\t\\n'\"\\033?""?/\\\\",
111 "a:b", "a\\\\b", "a' b", LQ_ENC RQ_ENC, LQ RQ },
112 { "", "\\0001\\0", 7, "simple", "\\t'\\t", " \\t\\n'\"\\033?""?/\\\\",
113 "a:b", "a\\\\b", "a' b", LQ_ENC RQ_ENC, LQ RQ },
114 { "", "\\0001\\0", 7, "simple", "\\t'\\t", " \\t\\n'\"\\033?""?/\\\\",
115 "a\\:b", "a\\\\b", "a' b", LQ_ENC RQ_ENC, LQ RQ } },
117 /* locale_quoting_style */
118 { { "''", "'\\0001\\0'", 9, "'simple'", "'\\t\\'\\t'",
119 "' \\t\\n\\'\"\\033?""?/\\\\'", "'a:b'", "'a\\\\b'", "'a\\' b'",
120 "'" LQ_ENC RQ_ENC "'", "'" LQ RQ "'" },
121 { "''", "'\\0001\\0'", 9, "'simple'", "'\\t\\'\\t'",
122 "' \\t\\n\\'\"\\033?""?/\\\\'", "'a:b'", "'a\\\\b'", "'a\\' b'",
123 "'" LQ_ENC RQ_ENC "'", "'" LQ RQ "'" },
124 { "''", "'\\0001\\0'", 9, "'simple'", "'\\t\\'\\t'",
125 "' \\t\\n\\'\"\\033?""?/\\\\'", "'a\\:b'", "'a\\\\b'", "'a\\' b'",
126 "'" LQ_ENC RQ_ENC "'", "'" LQ RQ "'" } },
128 /* clocale_quoting_style */
129 { { "\"\"", "\"\\0001\\0\"", 9, "\"simple\"", "\"\\t'\\t\"",
130 "\" \\t\\n'\\\"\\033?""?/\\\\\"", "\"a:b\"", "\"a\\\\b\"",
131 "\"a' b\"", "\"" LQ_ENC RQ_ENC "\"", "\"" LQ RQ "\"" },
132 { "\"\"", "\"\\0001\\0\"", 9, "\"simple\"", "\"\\t'\\t\"",
133 "\" \\t\\n'\\\"\\033?""?/\\\\\"", "\"a:b\"", "\"a\\\\b\"",
134 "\"a' b\"", "\"" LQ_ENC RQ_ENC "\"", "\"" LQ RQ "\"" },
135 { "\"\"", "\"\\0001\\0\"", 9, "\"simple\"", "\"\\t'\\t\"",
136 "\" \\t\\n'\\\"\\033?""?/\\\\\"", "\"a\\:b\"", "\"a\\\\b\"",
137 "\"a' b\"", "\"" LQ_ENC RQ_ENC "\"", "\"" LQ RQ "\"" } }
140 static struct result_groups flag_results[] = {
141 /* literal_quoting_style and QA_ELIDE_NULL_BYTES */
142 { { "", "1", 1, "simple", "\t'\t", " \t\n'\"\033?""?/\\",
143 "a:b", "a\\b", "a' b", LQ RQ, LQ RQ },
144 { "", "1", 1, "simple", "\t'\t", " \t\n'\"\033?""?/\\",
145 "a:b", "a\\b", "a' b", LQ RQ, LQ RQ },
146 { "", "1", 1, "simple", "\t'\t", " \t\n'\"\033?""?/\\",
147 "a:b", "a\\b", "a' b", LQ RQ, LQ RQ } },
149 /* c_quoting_style and QA_ELIDE_OUTER_QUOTES */
150 { { "", "\"\\0001\\0\"", 9, "simple", "\"\\t'\\t\"",
151 "\" \\t\\n'\\\"\\033?""?/\\\\\"", "a:b", "a\\b", "a' b",
152 "\"" LQ_ENC RQ_ENC "\"", LQ RQ },
153 { "", "\"\\0001\\0\"", 9, "simple", "\"\\t'\\t\"",
154 "\" \\t\\n'\\\"\\033?""?/\\\\\"", "a:b", "a\\b", "a' b",
155 "\"" LQ_ENC RQ_ENC "\"", LQ RQ },
156 { "", "\"\\0001\\0\"", 9, "simple", "\"\\t'\\t\"",
157 "\" \\t\\n'\\\"\\033?""?/\\\\\"", "\"a:b\"", "a\\b", "a' b",
158 "\"" LQ_ENC RQ_ENC "\"", LQ RQ } },
160 /* c_quoting_style and QA_SPLIT_TRIGRAPHS */
161 { { "\"\"", "\"\\0001\\0\"", 9, "\"simple\"", "\"\\t'\\t\"",
162 "\" \\t\\n'\\\"\\033?\"\"?/\\\\\"", "\"a:b\"", "\"a\\\\b\"",
163 "\"a' b\"", "\"" LQ_ENC RQ_ENC "\"", "\"" LQ RQ "\"" },
164 { "\"\"", "\"\\0001\\0\"", 9, "\"simple\"", "\"\\t'\\t\"",
165 "\" \\t\\n'\\\"\\033?\"\"?/\\\\\"", "\"a:b\"", "\"a\\\\b\"",
166 "\"a' b\"", "\"" LQ_ENC RQ_ENC "\"", "\"" LQ RQ "\"" },
167 { "\"\"", "\"\\0001\\0\"", 9, "\"simple\"", "\"\\t'\\t\"",
168 "\" \\t\\n'\\\"\\033?\"\"?/\\\\\"", "\"a\\:b\"", "\"a\\\\b\"",
169 "\"a' b\"", "\"" LQ_ENC RQ_ENC "\"", "\"" LQ RQ "\"" } }
172 static char const *custom_quotes[][2] = {
173 { "", "" },
174 { "'", "'" },
175 { "(", ")" },
176 { ":", " " },
177 { " ", ":" },
178 { "# ", "\n" },
179 { "\"'", "'\"" }
182 static struct result_groups custom_results[] = {
183 /* left_quote = right_quote = "" */
184 { { "", "\\0001\\0", 7, "simple", "\\t'\\t",
185 " \\t\\n'\"\\033?""?/\\\\", "a:b", "a\\\\b",
186 "a' b", LQ_ENC RQ_ENC, LQ RQ },
187 { "", "\\0001\\0", 7, "simple", "\\t'\\t",
188 " \\t\\n'\"\\033?""?/\\\\", "a:b", "a\\\\b",
189 "a' b", LQ_ENC RQ_ENC, LQ RQ },
190 { "", "\\0001\\0", 7, "simple", "\\t'\\t",
191 " \\t\\n'\"\\033?""?/\\\\", "a\\:b", "a\\\\b",
192 "a' b", LQ_ENC RQ_ENC, LQ RQ } },
194 /* left_quote = right_quote = "'" */
195 { { "''", "'\\0001\\0'", 9, "'simple'", "'\\t\\'\\t'",
196 "' \\t\\n\\'\"\\033?""?/\\\\'", "'a:b'", "'a\\\\b'",
197 "'a\\' b'", "'" LQ_ENC RQ_ENC "'", "'" LQ RQ "'" },
198 { "''", "'\\0001\\0'", 9, "'simple'", "'\\t\\'\\t'",
199 "' \\t\\n\\'\"\\033?""?/\\\\'", "'a:b'", "'a\\\\b'",
200 "'a\\' b'", "'" LQ_ENC RQ_ENC "'", "'" LQ RQ "'" },
201 { "''", "'\\0001\\0'", 9, "'simple'", "'\\t\\'\\t'",
202 "' \\t\\n\\'\"\\033?""?/\\\\'", "'a\\:b'", "'a\\\\b'",
203 "'a\\' b'", "'" LQ_ENC RQ_ENC "'", "'" LQ RQ "'" } },
205 /* left_quote = "(" and right_quote = ")" */
206 { { "()", "(\\0001\\0)", 9, "(simple)", "(\\t'\\t)",
207 "( \\t\\n'\"\\033?""?/\\\\)", "(a:b)", "(a\\\\b)",
208 "(a' b)", "(" LQ_ENC RQ_ENC ")", "(" LQ RQ ")" },
209 { "()", "(\\0001\\0)", 9, "(simple)", "(\\t'\\t)",
210 "( \\t\\n'\"\\033?""?/\\\\)", "(a:b)", "(a\\\\b)",
211 "(a' b)", "(" LQ_ENC RQ_ENC ")", "(" LQ RQ ")" },
212 { "()", "(\\0001\\0)", 9, "(simple)", "(\\t'\\t)",
213 "( \\t\\n'\"\\033?""?/\\\\)", "(a\\:b)", "(a\\\\b)",
214 "(a' b)", "(" LQ_ENC RQ_ENC ")", "(" LQ RQ ")" } },
216 /* left_quote = ":" and right_quote = " " */
217 { { ": ", ":\\0001\\0 ", 9, ":simple ", ":\\t'\\t ",
218 ":\\ \\t\\n'\"\\033?""?/\\\\ ", ":a:b ", ":a\\\\b ",
219 ":a'\\ b ", ":" LQ_ENC RQ_ENC " ", ":" LQ RQ " " },
220 { ": ", ":\\0001\\0 ", 9, ":simple ", ":\\t'\\t ",
221 ":\\ \\t\\n'\"\\033?""?/\\\\ ", ":a:b ", ":a\\\\b ",
222 ":a'\\ b ", ":" LQ_ENC RQ_ENC " ", ":" LQ RQ " " },
223 { ": ", ":\\0001\\0 ", 9, ":simple ", ":\\t'\\t ",
224 ":\\ \\t\\n'\"\\033?""?/\\\\ ", ":a\\:b ", ":a\\\\b ",
225 ":a'\\ b ", ":" LQ_ENC RQ_ENC " ", ":" LQ RQ " " } },
227 /* left_quote = " " and right_quote = ":" */
228 { { " :", " \\0001\\0:", 9, " simple:", " \\t'\\t:",
229 " \\t\\n'\"\\033?""?/\\\\:", " a\\:b:", " a\\\\b:",
230 " a' b:", " " LQ_ENC RQ_ENC ":", " " LQ RQ ":" },
231 { " :", " \\0001\\0:", 9, " simple:", " \\t'\\t:",
232 " \\t\\n'\"\\033?""?/\\\\:", " a\\:b:", " a\\\\b:",
233 " a' b:", " " LQ_ENC RQ_ENC ":", " " LQ RQ ":" },
234 { " :", " \\0001\\0:", 9, " simple:", " \\t'\\t:",
235 " \\t\\n'\"\\033?""?/\\\\:", " a\\:b:", " a\\\\b:",
236 " a' b:", " " LQ_ENC RQ_ENC ":", " " LQ RQ ":" } },
238 /* left_quote = "# " and right_quote = "\n" */
239 { { "# \n", "# \\0001\\0\n", 10, "# simple\n", "# \\t'\\t\n",
240 "# \\t\\n'\"\\033?""?/\\\\\n", "# a:b\n", "# a\\\\b\n",
241 "# a' b\n", "# " LQ_ENC RQ_ENC "\n", "# " LQ RQ "\n" },
242 { "# \n", "# \\0001\\0\n", 10, "# simple\n", "# \\t'\\t\n",
243 "# \\t\\n'\"\\033?""?/\\\\\n", "# a:b\n", "# a\\\\b\n",
244 "# a' b\n", "# " LQ_ENC RQ_ENC "\n", "# " LQ RQ "\n" },
245 { "# \n", "# \\0001\\0\n", 10, "# simple\n", "# \\t'\\t\n",
246 "# \\t\\n'\"\\033?""?/\\\\\n", "# a\\:b\n", "# a\\\\b\n",
247 "# a' b\n", "# " LQ_ENC RQ_ENC "\n", "# " LQ RQ "\n" } },
249 /* left_quote = "\"'" and right_quote = "'\"" */
250 { { "\"''\"", "\"'\\0001\\0'\"", 11, "\"'simple'\"", "\"'\\t'\\t'\"",
251 "\"' \\t\\n\\'\"\\033?""?/\\\\'\"", "\"'a:b'\"", "\"'a\\\\b'\"",
252 "\"'a' b'\"", "\"'" LQ_ENC RQ_ENC "'\"", "\"'" LQ RQ "'\"" },
253 { "\"''\"", "\"'\\0001\\0'\"", 11, "\"'simple'\"", "\"'\\t'\\t'\"",
254 "\"' \\t\\n\\'\"\\033?""?/\\\\'\"", "\"'a:b'\"", "\"'a\\\\b'\"",
255 "\"'a' b'\"", "\"'" LQ_ENC RQ_ENC "'\"", "\"'" LQ RQ "'\"" },
256 { "\"''\"", "\"'\\0001\\0'\"", 11, "\"'simple'\"", "\"'\\t'\\t'\"",
257 "\"' \\t\\n\\'\"\\033?""?/\\\\'\"", "\"'a\\:b'\"", "\"'a\\\\b'\"",
258 "\"'a' b'\"", "\"'" LQ_ENC RQ_ENC "'\"", "\"'" LQ RQ "'\"" } }
261 static char *
262 use_quote_double_quotes (const char *str, size_t *len)
264 char *p = *len == SIZE_MAX ? quotearg_char (str, '"')
265 : quotearg_char_mem (str, *len, '"');
266 *len = strlen (p);
267 return p;
271 main (_GL_UNUSED int argc, char *argv[])
273 int i;
274 bool ascii_only = MB_CUR_MAX == 1 && !isprint ((unsigned char) LQ[0]);
276 /* This part of the program is hard-wired to the C locale since it
277 does not call setlocale. However, according to POSIX, the use of
278 8-bit bytes in a character context in the C locale gives
279 unspecified results (that is, the C locale charset is allowed to
280 be unibyte with 8-bit bytes rejected [ASCII], unibyte with 8-bit
281 bytes being characters [often ISO-8859-1], or multibyte [often
282 UTF-8]). We assume that the latter two cases will be
283 indistinguishable in this test - that is, the LQ and RQ sequences
284 will pass through unchanged in either type of charset. So when
285 testing for quoting of str7, use the ascii_only flag to decide
286 what to expect for the 8-bit data being quoted. */
287 ASSERT (!isprint ('\033'));
288 for (i = literal_quoting_style; i <= clocale_quoting_style; i++)
290 set_quoting_style (NULL, (enum quoting_style) i);
291 if (!(i == locale_quoting_style || i == clocale_quoting_style)
292 || (strcmp (locale_charset (), "ASCII") == 0
293 || strcmp (locale_charset (), "ANSI_X3.4-1968") == 0))
295 compare_strings (use_quotearg_buffer, &results_g[i].group1,
296 ascii_only);
297 compare_strings (use_quotearg, &results_g[i].group2,
298 ascii_only);
299 if (i == c_quoting_style)
300 compare_strings (use_quote_double_quotes, &results_g[i].group2,
301 ascii_only);
302 compare_strings (use_quotearg_colon, &results_g[i].group3,
303 ascii_only);
307 set_quoting_style (NULL, literal_quoting_style);
308 ASSERT (set_quoting_flags (NULL, QA_ELIDE_NULL_BYTES) == 0);
309 compare_strings (use_quotearg_buffer, &flag_results[0].group1, ascii_only);
310 compare_strings (use_quotearg, &flag_results[0].group2, ascii_only);
311 compare_strings (use_quotearg_colon, &flag_results[0].group3, ascii_only);
313 set_quoting_style (NULL, c_quoting_style);
314 ASSERT (set_quoting_flags (NULL, QA_ELIDE_OUTER_QUOTES)
315 == QA_ELIDE_NULL_BYTES);
316 compare_strings (use_quotearg_buffer, &flag_results[1].group1, ascii_only);
317 compare_strings (use_quotearg, &flag_results[1].group2, ascii_only);
318 compare_strings (use_quote_double_quotes, &flag_results[1].group2,
319 ascii_only);
320 compare_strings (use_quotearg_colon, &flag_results[1].group3, ascii_only);
322 ASSERT (set_quoting_flags (NULL, QA_SPLIT_TRIGRAPHS)
323 == QA_ELIDE_OUTER_QUOTES);
324 compare_strings (use_quotearg_buffer, &flag_results[2].group1, ascii_only);
325 compare_strings (use_quotearg, &flag_results[2].group2, ascii_only);
326 compare_strings (use_quote_double_quotes, &flag_results[2].group2,
327 ascii_only);
328 compare_strings (use_quotearg_colon, &flag_results[2].group3, ascii_only);
330 ASSERT (set_quoting_flags (NULL, 0) == QA_SPLIT_TRIGRAPHS);
332 for (i = 0; i < sizeof custom_quotes / sizeof *custom_quotes; ++i)
334 set_custom_quoting (NULL,
335 custom_quotes[i][0], custom_quotes[i][1]);
336 compare_strings (use_quotearg_buffer, &custom_results[i].group1,
337 ascii_only);
338 compare_strings (use_quotearg, &custom_results[i].group2, ascii_only);
339 compare_strings (use_quotearg_colon, &custom_results[i].group3,
340 ascii_only);
344 /* Trigger the bug whereby quotearg_buffer would read beyond the NUL
345 that defines the end of the string being quoted. Use an input
346 string whose NUL is the last byte before an unreadable page. */
347 char *z = zerosize_ptr ();
349 if (z)
351 size_t q_len = 1024;
352 char *q = malloc (q_len + 1);
353 char buf[10];
354 memset (q, 'Q', q_len);
355 q[q_len] = 0;
357 /* Z points to the boundary between a readable/writable page
358 and one that is neither readable nor writable. Position
359 our string so its NUL is at the end of the writable one. */
360 char const *str = "____";
361 size_t s_len = strlen (str);
362 z -= s_len + 1;
363 memcpy (z, str, s_len + 1);
365 set_custom_quoting (NULL, q, q);
366 /* Whether this actually triggers a SEGV depends on the
367 implementation of memcmp: whether it compares only byte-at-
368 a-time, and from left to right (no SEGV) or some other way. */
369 size_t n = quotearg_buffer (buf, sizeof buf, z, SIZE_MAX, NULL);
370 ASSERT (n == s_len + 2 * q_len);
371 ASSERT (memcmp (buf, q, sizeof buf) == 0);
372 free (q);
376 quotearg_free ();
378 return test_exit_status;