commit 25a9500caba30aeb01ed4e8931a82dc6ae1efde1
parent 2f44c7e5c28a3e5b14c0367c95b0a33ffd6cc277
Author: aabacchus <ben@bvnf.space>
Date: Sat, 2 Oct 2021 17:13:32 +0100
check for extra cells
Diffstat:
1 file changed, 9 insertions(+), 0 deletions(-)
diff --git a/csv.c b/csv.c
@@ -69,6 +69,15 @@ read_data(FILE *f, float ***datap, int ncols) {
np = n;
}
x++;
+ if (x > ncols) {
+ /* extra cells in the row. eat up the rest of the row to avoid writing into
+ * unallocated memory */
+ fprintf(stderr, "warning: extra cells in row %d\n", y + 1);
+ while (c != '\n' && c != EOF)
+ c = fgetc(f);
+ if (c == EOF)
+ break;
+ }
if (c == '\n') {
if (x < ncols) {
fprintf(stderr, "warning: %d cells missing from row %d\n", ncols - x, y + 1);