diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2025-10-04 16:13:49 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2025-10-04 16:13:49 -0400 |
| commit | 4cb2ea78760fabcbf526dee5962a6bf4896639f3 (patch) | |
| tree | c86a6edbd59db3164deebcb3192a0dd830a67490 /src/stdlib | |
| parent | 70a0f59b9e97b303434047a43aa217889a5a6d61 (diff) | |
When reading a file by line, skip lines with invalid UTF8 instead of
failing
Diffstat (limited to 'src/stdlib')
| -rw-r--r-- | src/stdlib/paths.c | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/src/stdlib/paths.c b/src/stdlib/paths.c index ee85d5bb..d630ad7d 100644 --- a/src/stdlib/paths.c +++ b/src/stdlib/paths.c @@ -658,6 +658,7 @@ static Text_t _next_line(FILE **f) { char *line = NULL; size_t size = 0; +next_line:; ssize_t len = getline(&line, &size, *f); if (len <= 0) { _line_reader_cleanup(f); @@ -667,7 +668,10 @@ static Text_t _next_line(FILE **f) { while (len > 0 && (line[len - 1] == '\r' || line[len - 1] == '\n')) --len; - if (u8_check((uint8_t *)line, (size_t)len) != NULL) fail("Invalid UTF8!"); + if (u8_check((uint8_t *)line, (size_t)len) != NULL) { + // If there's invalid UTF8, skip this line and move to the next + goto next_line; + } Text_t line_text = Text$from_strn(line, (size_t)len); free(line); |
