From a53cf09ca106bf5cd8269cdac2dbb77f645bfb0b Mon Sep 17 00:00:00 2001 From: Collin Funk Date: Tue, 13 Oct 2026 21:13:10 -0700 Subject: [PATCH] maint: join: use a stricter COUNTED_BY on fields * src/join.c (struct line): Change the COUNTED_BY to use the nfields member instead of nfields_allocated. (extract_field): Increment the count before writing to the last field, otherwise -fsanitize=bounds would kill the program. --- src/join.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/join.c b/src/join.c index 999f248c8..e2b4e5cac 100644 --- a/src/join.c +++ b/src/join.c @@ -74,7 +74,7 @@ struct line struct linebuffer buf; /* The line itself. */ idx_t nfields; /* Number of elements in 'fields'. */ idx_t nfields_allocated; /* Number of elements allocated for 'fields'. */ - struct field *fields COUNTED_BY (nfields_allocated); + struct field *fields COUNTED_BY (nfields); }; /* One or more consecutive lines read from a file that all have the @@ -294,9 +294,9 @@ extract_field (struct line *line, char *field, idx_t len) if (line->nfields >= line->nfields_allocated) line->fields = xpalloc (line->fields, &line->nfields_allocated, 1, -1, sizeof *line->fields); - line->fields[line->nfields].beg = field; - line->fields[line->nfields].len = len; - ++(line->nfields); + idx_t const field_index = line->nfields++; + line->fields[field_index].beg = field; + line->fields[field_index].len = len; } static bool