* The format string uses field numbers, so we need to whiffle through it * and make sure everything's sane and lovely. */
| 5691 | * and make sure everything's sane and lovely. |
| 5692 | */ |
| 5693 | static int |
| 5694 | xo_parse_field_numbers (xo_handle_t *xop, const char *fmt, |
| 5695 | xo_field_info_t *fields, unsigned num_fields) |
| 5696 | { |
| 5697 | xo_field_info_t *xfip; |
| 5698 | unsigned field, fnum; |
| 5699 | uint64_t bits = 0; |
| 5700 | const uint64_t one = 1; /* Avoid 1ULL */ |
| 5701 | |
| 5702 | for (xfip = fields, field = 0; field < num_fields; xfip++, field++) { |
| 5703 | /* Fields default to 1:1 with natural position */ |
| 5704 | if (xfip->xfi_fnum == 0) |
| 5705 | xfip->xfi_fnum = field + 1; |
| 5706 | else if (xfip->xfi_fnum > num_fields) { |
| 5707 | xo_failure(xop, "field number exceeds number of fields: '%s'", fmt); |
| 5708 | return -1; |
| 5709 | } |
| 5710 | |
| 5711 | fnum = xfip->xfi_fnum - 1; /* Move to zero origin */ |
| 5712 | if (fnum < 64) { /* Only test what fits */ |
| 5713 | if (bits & (one << fnum)) { |
| 5714 | xo_failure(xop, "field number %u reused: '%s'", |
| 5715 | xfip->xfi_fnum, fmt); |
| 5716 | return -1; |
| 5717 | } |
| 5718 | bits |= one << fnum; |
| 5719 | } |
| 5720 | } |
| 5721 | |
| 5722 | return 0; |
| 5723 | } |
| 5724 | |
| 5725 | static int |
| 5726 | xo_parse_fields (xo_handle_t *xop, xo_field_info_t *fields, |
no test coverage detected