| 476 | } |
| 477 | |
| 478 | static bencode_item_t *__bencode_decode_dictionary(bencode_buffer_t *buf, const char *s, const char *end) { |
| 479 | bencode_item_t *ret, *key, *value; |
| 480 | struct __bencode_hash *hash; |
| 481 | |
| 482 | if (*s != 'd') |
| 483 | return NULL; |
| 484 | s++; |
| 485 | |
| 486 | ret = __bencode_item_alloc(buf, sizeof(*hash)); |
| 487 | if (!ret) |
| 488 | return NULL; |
| 489 | __bencode_dictionary_init(ret); |
| 490 | ret->value = 1; |
| 491 | hash = (void *) ret->__buf; |
| 492 | memset(hash, 0, sizeof(*hash)); |
| 493 | |
| 494 | while (s < end) { |
| 495 | key = __bencode_decode(buf, s, end); |
| 496 | if (!key) |
| 497 | return NULL; |
| 498 | s += key->str_len; |
| 499 | if (key->type == BENCODE_END_MARKER) |
| 500 | break; |
| 501 | if (key->type != BENCODE_STRING) |
| 502 | return NULL; |
| 503 | __bencode_container_add(ret, key); |
| 504 | |
| 505 | if (s >= end) |
| 506 | return NULL; |
| 507 | value = __bencode_decode(buf, s, end); |
| 508 | if (!value) |
| 509 | return NULL; |
| 510 | s += value->str_len; |
| 511 | if (value->type == BENCODE_END_MARKER) |
| 512 | return NULL; |
| 513 | __bencode_container_add(ret, value); |
| 514 | |
| 515 | __bencode_hash_insert(key, hash); |
| 516 | } |
| 517 | |
| 518 | return ret; |
| 519 | } |
| 520 | |
| 521 | static bencode_item_t *__bencode_decode_list(bencode_buffer_t *buf, const char *s, const char *end) { |
| 522 | bencode_item_t *ret, *item; |
no test coverage detected