ESH

Executive Shell
git clone http://git.omkov.net/ESH
Log | Tree | Refs | README | Download

AuthorJamozed <[email protected]>
Date2021-09-09 02:08:52
Commitfd110664b11917f1f75b936370d7e25b67d5b4e2
Parent2341ac552803feba98a1047d9f5012ceb0ea37ce

Fix underallocation of memory

Diffstat

M src/main.c | 4 ----
M src/parse.c | 6 ++----

2 files changed, 2 insertions, 8 deletions

diff --git a/src/main.c b/src/main.c
index 22cbd1a..1057399 100644
--- a/src/main.c
+++ b/src/main.c
@@ -41,9 +41,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE.
 #include <errno.h>
 #include <setjmp.h>
 #include <signal.h>
-#include <stdbool.h>
-#include <stddef.h>
-#include <stdint.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -88,7 +85,6 @@ int main(int ac, char *av[]) { (void)(ac); A0 = av[0];
 		lex l = lex_init(line, strlen((char *)line));
 		if (Lflag) { lex_debug(&l); goto loop; }
 
-		/* FIXME there is a memory leak somewhere */
 		ast *a = parse(&l); if (!a) { goto loop; }
 		if (Pflag) { ast_debug(a); goto loop; }
 
diff --git a/src/parse.c b/src/parse.c
index 92a58a6..a327ab3 100644
--- a/src/parse.c
+++ b/src/parse.c
@@ -34,10 +34,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE.
 
 #include "cll/cll.h"
 
-#include <ctype.h>
 #include <stdio.h>
 #include <stdlib.h>
-#include <string.h>
 
 typedef struct { u8 **a; UINT al; } arr;
 
@@ -77,8 +75,8 @@ static ast *parse_com(lex *l) {
 
 /* Push a string to the end of an array. */
 void arr_push(arr *a, u8 *s) {
-	a->a = realloc(a->a, a->al * sizeof (*a->a));
-	a->a[a->al] = s; a->al += 1;
+	a->a = realloc(a->a, (a->al += 1) * sizeof (*a->a));
+	a->a[a->al - 1] = s;
 }
 
 /* Print parser debug output with an indent. */