| 319 | } |
| 320 | |
| 321 | struct match_attr *parse_attr_line(const char *line, const char *src, |
| 322 | int lineno, unsigned flags) |
| 323 | { |
| 324 | size_t namelen, num_attr, i; |
| 325 | const char *cp, *name, *states; |
| 326 | struct match_attr *res = NULL; |
| 327 | int is_macro; |
| 328 | struct strbuf pattern = STRBUF_INIT; |
| 329 | |
| 330 | cp = line + strspn(line, blank); |
| 331 | if (!*cp || *cp == '#') |
| 332 | return NULL; |
| 333 | name = cp; |
| 334 | |
| 335 | if (strlen(line) >= ATTR_MAX_LINE_LENGTH) { |
| 336 | warning(_("ignoring overly long attributes line %d"), lineno); |
| 337 | return NULL; |
| 338 | } |
| 339 | |
| 340 | if (*cp == '"' && !unquote_c_style(&pattern, name, &states)) { |
| 341 | name = pattern.buf; |
| 342 | namelen = pattern.len; |
| 343 | } else { |
| 344 | namelen = strcspn(name, blank); |
| 345 | states = name + namelen; |
| 346 | } |
| 347 | |
| 348 | if (strlen(ATTRIBUTE_MACRO_PREFIX) < namelen && |
| 349 | starts_with(name, ATTRIBUTE_MACRO_PREFIX)) { |
| 350 | if (!(flags & READ_ATTR_MACRO_OK)) { |
| 351 | fprintf_ln(stderr, _("%s not allowed: %s:%d"), |
| 352 | name, src, lineno); |
| 353 | goto fail_return; |
| 354 | } |
| 355 | is_macro = 1; |
| 356 | name += strlen(ATTRIBUTE_MACRO_PREFIX); |
| 357 | name += strspn(name, blank); |
| 358 | namelen = strcspn(name, blank); |
| 359 | if (!attr_name_valid(name, namelen) || attr_name_reserved(name)) { |
| 360 | report_invalid_attr(name, namelen, src, lineno); |
| 361 | goto fail_return; |
| 362 | } |
| 363 | } |
| 364 | else |
| 365 | is_macro = 0; |
| 366 | |
| 367 | states += strspn(states, blank); |
| 368 | |
| 369 | /* First pass to count the attr_states */ |
| 370 | for (cp = states, num_attr = 0; *cp; num_attr++) { |
| 371 | cp = parse_attr(src, lineno, cp, NULL); |
| 372 | if (!cp) |
| 373 | goto fail_return; |
| 374 | } |
| 375 | |
| 376 | res = xcalloc(1, st_add3(sizeof(*res), |
| 377 | st_mult(sizeof(struct attr_state), num_attr), |
| 378 | is_macro ? 0 : namelen + 1)); |
no test coverage detected