| 1123 | } |
| 1124 | |
| 1125 | static int yaml_build_lines(yaml_doc_t *doc) { |
| 1126 | size_t count = yaml_count_lines(doc); |
| 1127 | if (count == 0U) { |
| 1128 | yaml_detect_eol(doc); |
| 1129 | return 0; |
| 1130 | } |
| 1131 | if (count > SIZE_MAX / sizeof(yaml_line_t)) { |
| 1132 | return YAML_ERROR; |
| 1133 | } |
| 1134 | yaml_line_t *lines = (yaml_line_t *)calloc(count, sizeof(*lines)); |
| 1135 | if (!lines) { |
| 1136 | return YAML_ERROR; |
| 1137 | } |
| 1138 | |
| 1139 | size_t line_index = 0U; |
| 1140 | size_t start = 0U; |
| 1141 | while (start < doc->len && line_index < count) { |
| 1142 | start = yaml_parse_line(doc, start, &lines[line_index++]); |
| 1143 | } |
| 1144 | if (start != doc->len || line_index != count) { |
| 1145 | free(lines); |
| 1146 | return YAML_ERROR; |
| 1147 | } |
| 1148 | doc->lines = lines; |
| 1149 | doc->line_count = count; |
| 1150 | yaml_detect_eol(doc); |
| 1151 | return 0; |
| 1152 | } |
| 1153 | |
| 1154 | static void yaml_doc_free(yaml_doc_t *doc) { |
| 1155 | free(doc->lines); |
no test coverage detected