commit c530813b9987540f5d82e43263b34e646045c5cd
parent 6a8c20979854892b4e22de44281ffb14c2a0faaf
Author: Pavel Renev <an2qzavok@gmail.com>
Date: Tue, 29 Sep 2020 18:57:04 +0000
fixed crash on empty cell data
Diffstat:
1 file changed, 11 insertions(+), 9 deletions(-)
diff --git a/cells.c b/cells.c
@@ -117,15 +117,15 @@ table_get(Stack *T, Addr addr)
Stack*
table_read(char *path)
{
- Stack *T, *N;
+ Stack *T;
Value *v;
char b, *buf;
long bufsize, x, y;
int fd;
- N = T = empty_table();
+ T = empty_table();
+ buf = mallocz(1, 1);
bufsize = 0;
x = 0;
- buf = nil;
y = 0;
fd = open(path, OREAD);
if (fd == 0) return nil;
@@ -136,7 +136,8 @@ table_read(char *path)
*v = mk_value(xy2addr(x, y), buf);
push(T, v);
bufsize = 0;
- buf = realloc(buf, 0);
+ buf = realloc(buf, 1);
+ *buf = 0;
x++;
break;
case '\n':
@@ -144,7 +145,8 @@ table_read(char *path)
*v = mk_value(xy2addr(x, y), buf);
push(T, v);
bufsize = 0;
- buf = realloc(buf, 0);
+ buf = realloc(buf, 1);
+ *buf = 0;
y++;
x = 0;
break;
@@ -156,14 +158,14 @@ table_read(char *path)
}
}
if (buf != nil) {
- N = table_put(T, mk_value(xy2addr(x, y), buf));
- free_table(T);
- free(T);
+ v = malloc(sizeof(Value));
+ *v = mk_value(xy2addr(x, y), buf);
+ push(T, v);
}
realloc(buf, 0);
close(fd);
- return N;
+ return T;
}