From 6ea02e2f75422d67548836670082daa8e8129102 Mon Sep 17 00:00:00 2001 From: Bad Diode Date: Tue, 19 Oct 2021 18:30:39 +0200 Subject: Change environments to use darray.h --- src/bootstrap/main.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'src/bootstrap/main.c') diff --git a/src/bootstrap/main.c b/src/bootstrap/main.c index c2c88d6..73a9244 100755 --- a/src/bootstrap/main.c +++ b/src/bootstrap/main.c @@ -207,16 +207,12 @@ run_file(char *file_name) { void run_stdin(void) { size_t buf_size = 0; - size_t buf_cap = STDIN_BUF_CAP; - char *source = malloc(buf_cap * sizeof(char)); + char *source = NULL; + array_init(source, STDIN_BUF_CAP); char c; while ((c = getchar()) != EOF) { - if (buf_size == buf_cap) { - buf_cap *= 2; - source = realloc(source, buf_cap * sizeof(char)); - } - source[buf_size] = c; + array_push(source, c); buf_size++; } @@ -240,7 +236,7 @@ run_stdin(void) { errors_n = 0; } - free(source); + array_free(source); } #ifndef BIN_NAME -- cgit v1.2.1