| 1072 | } |
| 1073 | |
| 1074 | static int yaml_build_lines(yaml_doc_t *doc) { |
| 1075 | size_t count = yaml_count_lines(doc); |
| 1076 | if (count == 0U) { |
| 1077 | yaml_detect_eol(doc); |
| 1078 | return 0; |
| 1079 | } |
| 1080 | if (count > SIZE_MAX / sizeof(yaml_line_t)) { |
| 1081 | return YAML_ERROR; |
| 1082 | } |
| 1083 | yaml_line_t *lines = (yaml_line_t *)calloc(count, sizeof(*lines)); |
| 1084 | if (!lines) { |
| 1085 | return YAML_ERROR; |
| 1086 | } |
| 1087 | |
| 1088 | size_t line_index = 0U; |
| 1089 | size_t start = 0U; |
| 1090 | while (start < doc->len && line_index < count) { |
| 1091 | start = yaml_parse_line(doc, start, &lines[line_index++]); |
| 1092 | } |
| 1093 | if (start != doc->len || line_index != count) { |
| 1094 | free(lines); |
| 1095 | return YAML_ERROR; |
| 1096 | } |
| 1097 | doc->lines = lines; |
| 1098 | doc->line_count = count; |
| 1099 | yaml_detect_eol(doc); |
| 1100 | return 0; |
| 1101 | } |
| 1102 | |
| 1103 | static void yaml_doc_free(yaml_doc_t *doc) { |
| 1104 | free(doc->lines); |
no test coverage detected