Try to extract a canonical section header from a "## Header" line. * Returns heap-allocated header string if canonical, NULL otherwise. */
| 7824 | /* Try to extract a canonical section header from a "## Header" line. |
| 7825 | * Returns heap-allocated header string if canonical, NULL otherwise. */ |
| 7826 | static char *adr_try_section_header(const char *line, int line_len) { |
| 7827 | if (line_len <= ST_HEADER_PREFIX || line[0] != '#' || line[SKIP_ONE] != '#' || |
| 7828 | line[PAIR_LEN] != ' ') { |
| 7829 | return NULL; |
| 7830 | } |
| 7831 | char header[CBM_SZ_64]; |
| 7832 | int hlen = line_len - ST_HEADER_PREFIX; |
| 7833 | if (hlen >= (int)sizeof(header)) { |
| 7834 | hlen = (int)sizeof(header) - SKIP_ONE; |
| 7835 | } |
| 7836 | memcpy(header, line + 3, hlen); |
| 7837 | header[hlen] = '\0'; |
| 7838 | while (hlen > 0 && (header[hlen - SKIP_ONE] == ' ' || header[hlen - SKIP_ONE] == '\t' || |
| 7839 | header[hlen - SKIP_ONE] == '\r')) { |
| 7840 | header[--hlen] = '\0'; |
| 7841 | } |
| 7842 | if (!is_canonical_section(header)) { |
| 7843 | return NULL; |
| 7844 | } |
| 7845 | return heap_strdup(header); |
| 7846 | } |
| 7847 | |
| 7848 | /* Append a line to the current section content buffer. */ |
| 7849 | static void adr_append_line(char *buf, int buf_sz, int *len, const char *line, int line_len) { |
no test coverage detected