Try to extract a canonical section header from a "## Header" line. * Returns heap-allocated header string if canonical, NULL otherwise. */
| 5685 | /* Try to extract a canonical section header from a "## Header" line. |
| 5686 | * Returns heap-allocated header string if canonical, NULL otherwise. */ |
| 5687 | static char *adr_try_section_header(const char *line, int line_len) { |
| 5688 | if (line_len <= ST_HEADER_PREFIX || line[0] != '#' || line[SKIP_ONE] != '#' || |
| 5689 | line[PAIR_LEN] != ' ') { |
| 5690 | return NULL; |
| 5691 | } |
| 5692 | char header[CBM_SZ_64]; |
| 5693 | int hlen = line_len - ST_HEADER_PREFIX; |
| 5694 | if (hlen >= (int)sizeof(header)) { |
| 5695 | hlen = (int)sizeof(header) - SKIP_ONE; |
| 5696 | } |
| 5697 | memcpy(header, line + 3, hlen); |
| 5698 | header[hlen] = '\0'; |
| 5699 | while (hlen > 0 && (header[hlen - SKIP_ONE] == ' ' || header[hlen - SKIP_ONE] == '\t' || |
| 5700 | header[hlen - SKIP_ONE] == '\r')) { |
| 5701 | header[--hlen] = '\0'; |
| 5702 | } |
| 5703 | if (!is_canonical_section(header)) { |
| 5704 | return NULL; |
| 5705 | } |
| 5706 | return heap_strdup(header); |
| 5707 | } |
| 5708 | |
| 5709 | /* Append a line to the current section content buffer. */ |
| 5710 | static void adr_append_line(char *buf, int buf_sz, int *len, const char *line, int line_len) { |
no test coverage detected