MCPcopy Create free account
hub / github.com/apache/httpd / check_macro_arguments

Function check_macro_arguments

modules/core/mod_macro.c:233–286  ·  view source on GitHub ↗

generates an error on macro with two arguments of the same name. generates an error if a macro argument name is empty. generates a warning if arguments name prefixes conflict. generates a warning if the first char of an argument is not in ARG_PREFIX */

Source from the content-addressed store, hash-verified

231 generates a warning if the first char of an argument is not in ARG_PREFIX
232*/
233static const char *check_macro_arguments(apr_pool_t * pool,
234 const ap_macro_t * macro)
235{
236 char **tab = (char **) macro->arguments->elts;
237 int nelts = macro->arguments->nelts;
238 int i;
239
240 for (i = 0; i < nelts; i++) {
241 size_t ltabi = strlen(tab[i]);
242 int j;
243
244 if (ltabi == 0) {
245 return apr_psprintf(pool,
246 "macro '%s' (%s): empty argument #%d name",
247 macro->name, macro->location, i + 1);
248 }
249 else if (!looks_like_an_argument(tab[i])) {
250 ap_log_error(APLOG_MARK, APLOG_WARNING, 0, NULL, APLOGNO(02796)
251 "macro '%s' (%s) "
252 "argument name '%s' (#%d) without expected prefix, "
253 "better prefix argument names with one of '%s'.",
254 macro->name, macro->location,
255 tab[i], i + 1, ARG_PREFIX);
256 }
257
258 for (j = i + 1; j < nelts; j++) {
259 size_t ltabj = strlen(tab[j]);
260
261 /* must not use the same argument name twice */
262 if (!strcmp(tab[i], tab[j])) {
263 return apr_psprintf(pool,
264 "argument name conflict in macro '%s' (%s): "
265 "argument '%s': #%d and #%d, "
266 "change argument names!",
267 macro->name, macro->location,
268 tab[i], i + 1, j + 1);
269 }
270
271 /* warn about common prefix, but only if non empty names */
272 if (ltabi && ltabj &&
273 !strncmp(tab[i], tab[j], ltabi < ltabj ? ltabi : ltabj)) {
274 ap_log_error(APLOG_MARK, APLOG_WARNING,
275 0, NULL, APLOGNO(02797)
276 "macro '%s' (%s): "
277 "argument name prefix conflict (%s #%d and %s #%d), "
278 "be careful about your macro definition!",
279 macro->name, macro->location,
280 tab[i], i + 1, tab[j], j + 1);
281 }
282 }
283 }
284
285 return NULL;
286}
287
288/*
289 warn about empty strings in array. could be legitimate.

Callers 1

macro_sectionFunction · 0.85

Calls 2

looks_like_an_argumentFunction · 0.85
ap_log_errorFunction · 0.50

Tested by

no test coverage detected