From 4cb2ea78760fabcbf526dee5962a6bf4896639f3 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Sat, 4 Oct 2025 16:13:49 -0400 Subject: When reading a file by line, skip lines with invalid UTF8 instead of failing --- src/stdlib/paths.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src') 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); -- cgit v1.2.3