* 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. */
--
2.56.0