| 590 | } |
| 591 | |
| 592 | static bencode_item_t *__bencode_decode_string(bencode_buffer_t *buf, const char *s, const char *end) { |
| 593 | unsigned long int sl; |
| 594 | char *convend; |
| 595 | const char *orig = s; |
| 596 | bencode_item_t *ret; |
| 597 | |
| 598 | if (*s == '0') { |
| 599 | sl = 0; |
| 600 | s++; |
| 601 | goto colon; |
| 602 | } |
| 603 | |
| 604 | sl = strtoul(s, &convend, 10); |
| 605 | if (convend == s) |
| 606 | return NULL; |
| 607 | s += (convend - s); |
| 608 | |
| 609 | colon: |
| 610 | if (s >= end) |
| 611 | return NULL; |
| 612 | if (*s != ':') |
| 613 | return NULL; |
| 614 | s++; |
| 615 | |
| 616 | if (s + sl > end) |
| 617 | return NULL; |
| 618 | |
| 619 | ret = __bencode_item_alloc(buf, 0); |
| 620 | if (!ret) |
| 621 | return NULL; |
| 622 | ret->type = BENCODE_STRING; |
| 623 | ret->iov[0].iov_base = (void *) orig; |
| 624 | ret->iov[0].iov_len = s - orig; |
| 625 | ret->iov[1].iov_base = (void *) s; |
| 626 | ret->iov[1].iov_len = sl; |
| 627 | ret->iov_cnt = 2; |
| 628 | ret->str_len = s - orig + sl; |
| 629 | |
| 630 | return ret; |
| 631 | } |
| 632 | |
| 633 | static bencode_item_t *__bencode_decode(bencode_buffer_t *buf, const char *s, const char *end) { |
| 634 | if (s >= end) |
no test coverage detected