mirror of
https://git.savannah.gnu.org/git/coreutils.git
synced 2026-10-24 02:08:57 +03:00
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.
This commit is contained in:
@@ -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. */
|
||||
|
||||
Reference in New Issue
Block a user