Classify one span header. seen[] marks the declared tables the span has * already supplied, so a second copy is refused instead of guessed at. */
| 2012 | /* Classify one span header. seen[] marks the declared tables the span has |
| 2013 | * already supplied, so a second copy is refused instead of guessed at. */ |
| 2014 | static int toml_managed_classify(const toml_managed_span_t *span, const toml_header_t *header, |
| 2015 | unsigned char *seen, int *kind, size_t *table) { |
| 2016 | size_t exact = 0U; |
| 2017 | int exact_taken = 0; |
| 2018 | size_t parent = 0U; |
| 2019 | size_t parent_depth = 0U; |
| 2020 | int result = TOML_EDIT_OK; |
| 2021 | size_t pos = span->owned_first; |
| 2022 | for (size_t index = 1U; pos < span->owned_len && result == TOML_EDIT_OK; ++index) { |
| 2023 | toml_section_t declared; |
| 2024 | if (toml_section_at(span->owned, pos, span->owned_len, &declared) != TOML_EDIT_OK) { |
| 2025 | return TOML_EDIT_ERR; |
| 2026 | } |
| 2027 | pos = declared.end; |
| 2028 | const toml_key_path_t *path = &declared.header.path; |
| 2029 | if (toml_key_path_equal(path, &header->path)) { |
| 2030 | if (declared.header.array != header->array) { |
| 2031 | result = TOML_EDIT_ERR; |
| 2032 | } else if (!seen[index] && exact == 0U) { |
| 2033 | exact = index; |
| 2034 | } else { |
| 2035 | exact_taken = 1; |
| 2036 | } |
| 2037 | } else if (toml_key_path_has_prefix(&header->path, path)) { |
| 2038 | if (declared.header.array) { |
| 2039 | result = TOML_EDIT_ERR; |
| 2040 | } else if (path->count > parent_depth) { |
| 2041 | parent = index; |
| 2042 | parent_depth = path->count; |
| 2043 | } |
| 2044 | } |
| 2045 | toml_header_dispose(&declared.header); |
| 2046 | } |
| 2047 | if (result != TOML_EDIT_OK || (exact == 0U && exact_taken)) { |
| 2048 | return TOML_EDIT_ERR; |
| 2049 | } |
| 2050 | if (exact != 0U) { |
| 2051 | seen[exact] = 1U; |
| 2052 | } |
| 2053 | *kind = exact != 0U ? TOML_SPAN_OWNED : parent != 0U ? TOML_SPAN_ATTACHED : TOML_SPAN_FOREIGN; |
| 2054 | *table = exact != 0U ? exact : parent; |
| 2055 | return TOML_EDIT_OK; |
| 2056 | } |
| 2057 | |
| 2058 | /* Sets *written when the declared table assigns key; a key that only shares |
| 2059 | * a dotted prefix with one it assigns would redefine it and is refused. */ |
no test coverage detected