Try to extract a canonical section header from a "## Header" line. * Returns heap-allocated header string if canonical, NULL otherwise. */
| 11013 | /* Try to extract a canonical section header from a "## Header" line. |
| 11014 | * Returns heap-allocated header string if canonical, NULL otherwise. */ |
| 11015 | static char *adr_try_section_header(const char *line, int line_len) { |
| 11016 | if (line_len <= ST_HEADER_PREFIX || line[0] != '#' || line[SKIP_ONE] != '#' || |
| 11017 | line[PAIR_LEN] != ' ') { |
| 11018 | return NULL; |
| 11019 | } |
| 11020 | char header[CBM_SZ_64]; |
| 11021 | int hlen = line_len - ST_HEADER_PREFIX; |
| 11022 | if (hlen >= (int)sizeof(header)) { |
| 11023 | hlen = (int)sizeof(header) - SKIP_ONE; |
| 11024 | } |
| 11025 | memcpy(header, line + 3, hlen); |
| 11026 | header[hlen] = '\0'; |
| 11027 | while (hlen > 0 && (header[hlen - SKIP_ONE] == ' ' || header[hlen - SKIP_ONE] == '\t' || |
| 11028 | header[hlen - SKIP_ONE] == '\r')) { |
| 11029 | header[--hlen] = '\0'; |
| 11030 | } |
| 11031 | if (!is_canonical_section(header)) { |
| 11032 | return NULL; |
| 11033 | } |
| 11034 | return heap_strdup(header); |
| 11035 | } |
| 11036 | |
| 11037 | /* Append a line to the current section content buffer. */ |
| 11038 | static void adr_append_line(char *buf, int buf_sz, int *len, const char *line, int line_len) { |
no test coverage detected