From e3dd28f7902c86b91df1a2af7143f98e736d8ced Mon Sep 17 00:00:00 2001 From: Collin Funk Date: Fri, 16 Oct 2026 00:15:31 -0700 Subject: [PATCH] maint: ptx: use a stricter COUNTED_BY for the word table * src/ptx.c (WORD_TABLE): Change the COUNTED_BY to use the length member instead of alloc. (digest_word_file): Increment the length before appending to the table otherwise -fsanitize=bounds would kill the program. --- src/ptx.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/ptx.c b/src/ptx.c index 7e0ce8121..7a3e43561 100644 --- a/src/ptx.c +++ b/src/ptx.c @@ -120,7 +120,7 @@ typedef struct { idx_t alloc; /* allocated length */ idx_t length; /* number of used entries */ - WORD *start COUNTED_BY (alloc); /* array of WORDs */ + WORD *start COUNTED_BY (length); /* array of WORDs */ } WORD_TABLE; @@ -695,9 +695,9 @@ digest_word_file (char const *file_name, WORD_TABLE *table) if (table->length == table->alloc) table->start = xpalloc (table->start, &table->alloc, 1, -1, sizeof *table->start); - table->start[table->length].start = word_start; - table->start[table->length].size = cursor - word_start; - table->length++; + idx_t const table_idx = table->length++; + table->start[table_idx].start = word_start; + table->start[table_idx].size = cursor - word_start; } /* This test allows for an incomplete line at end of file. */