From e9f5910f1fba8d194ea34d585930a74890a11a90 Mon Sep 17 00:00:00 2001 From: Rene Kita Date: Mon, 4 Oct 2021 09:45:33 +0200 Subject: [PATCH] Ensure VLA size is at least one (again) This is the same issue as commit 12c7b62a427 and should have been included there. 'maxcol' can be -1 which results in a size of 0. The array is never accessed with 'maxcol < 0', but zero length variable length arrays are undefined behaviour. --- table.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/table.c b/table.c index 6150d1f..a8e6598 100644 --- a/table.c +++ b/table.c @@ -1262,7 +1262,8 @@ check_table_width(struct table *t, double *newwidth, MAT * minv, int itr) int corr = 0; struct table_cell *cell = &t->cell; #ifdef __GNUC__ - short orgwidth[t->maxcol + 1], corwidth[t->maxcol + 1]; + short orgwidth[t->maxcol >= 0 ? t->maxcol + 1 : 1]; + short corwidth[t->maxcol >= 0 ? t->maxcol + 1 : 1]; short cwidth[cell->maxcell >= 0 ? cell->maxcell + 1 : 1]; double swidth[cell->maxcell >= 0 ? cell->maxcell + 1 : 1]; #else /* __GNUC__ */ @@ -1615,7 +1616,7 @@ int get_table_width(struct table *t, short *orgwidth, short *cellwidth, int flag) { #ifdef __GNUC__ - short newwidth[t->maxcol + 1]; + short newwidth[t->maxcol >= 0 ? t->maxcol + 1 : 1]; #else /* not __GNUC__ */ short newwidth[MAXCOL]; #endif /* not __GNUC__ */