* Parse signed/unsigned integers 8 to 64-bit long. * * Last argument (ctx->args) is retrieved to determine integer type and * storage location. */
| 10767 | * storage location. |
| 10768 | */ |
| 10769 | static int |
| 10770 | parse_int(struct context *ctx, const struct token *token, |
| 10771 | const char *str, unsigned int len, |
| 10772 | void *buf, unsigned int size) |
| 10773 | { |
| 10774 | const struct arg *arg = pop_args(ctx); |
| 10775 | uintmax_t u; |
| 10776 | char *end; |
| 10777 | |
| 10778 | (void)token; |
| 10779 | /* Argument is expected. */ |
| 10780 | if (!arg) |
| 10781 | return -1; |
| 10782 | errno = 0; |
| 10783 | u = arg->sign ? |
| 10784 | (uintmax_t)strtoimax(str, &end, 0) : |
| 10785 | strtoumax(str, &end, 0); |
| 10786 | if (errno || (size_t)(end - str) != len) |
| 10787 | goto error; |
| 10788 | if (arg->bounded && |
| 10789 | ((arg->sign && ((intmax_t)u < (intmax_t)arg->min || |
| 10790 | (intmax_t)u > (intmax_t)arg->max)) || |
| 10791 | (!arg->sign && (u < arg->min || u > arg->max)))) |
| 10792 | goto error; |
| 10793 | if (!ctx->object) |
| 10794 | return len; |
| 10795 | if (arg->mask) { |
| 10796 | if (!arg_entry_bf_fill(ctx->object, u, arg) || |
| 10797 | !arg_entry_bf_fill(ctx->objmask, -1, arg)) |
| 10798 | goto error; |
| 10799 | return len; |
| 10800 | } |
| 10801 | buf = (uint8_t *)ctx->object + arg->offset; |
| 10802 | size = arg->size; |
| 10803 | if (u > RTE_LEN2MASK(size * CHAR_BIT, uint64_t)) |
| 10804 | return -1; |
| 10805 | objmask: |
| 10806 | switch (size) { |
| 10807 | case sizeof(uint8_t): |
| 10808 | *(uint8_t *)buf = u; |
| 10809 | break; |
| 10810 | case sizeof(uint16_t): |
| 10811 | *(uint16_t *)buf = arg->hton ? rte_cpu_to_be_16(u) : u; |
| 10812 | break; |
| 10813 | case sizeof(uint8_t [3]): |
| 10814 | #if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN |
| 10815 | if (!arg->hton) { |
| 10816 | ((uint8_t *)buf)[0] = u; |
| 10817 | ((uint8_t *)buf)[1] = u >> 8; |
| 10818 | ((uint8_t *)buf)[2] = u >> 16; |
| 10819 | break; |
| 10820 | } |
| 10821 | #endif |
| 10822 | ((uint8_t *)buf)[0] = u >> 16; |
| 10823 | ((uint8_t *)buf)[1] = u >> 8; |
| 10824 | ((uint8_t *)buf)[2] = u; |
| 10825 | break; |
| 10826 | case sizeof(uint32_t): |
no test coverage detected