From c4ee664d0b2f4e118106fdd49eb50d9fb3eaeee3 Mon Sep 17 00:00:00 2001 From: Tomasz Kramkowski Date: Thu, 2 May 2024 21:08:11 +0100 Subject: Don't check parser_t.c against EOF parser_t.c is a char which may be unsigned on some platforms and therefore incapable of holding EOF. This field is only ever set from parser_t.source which is a char array, which only ever originates from {main,strquote,include} -> parser_pp -> {init_parser,parser_reset} which all assign it from char arrays. This means it should never be EOF, so the check can be dropped. Also update the documentation so it matches. --- src/stem.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'src') diff --git a/src/stem.c b/src/stem.c index 651d624..f623ae7 100644 --- a/src/stem.c +++ b/src/stem.c @@ -331,8 +331,6 @@ value_t *parser_get_next(parser_t *p) { return parse_quote(p); case '\0': return NULL; - case EOF: - return NULL; default: return parse_word(p); } -- cgit From 94f7d92631d87f968ffd559b2302aa1eb7cf840c Mon Sep 17 00:00:00 2001 From: Tomasz Kramkowski Date: Thu, 2 May 2024 21:24:20 +0100 Subject: Initialise getdelim buf pointers to NULL getdelim can either be passed NULL or a malloc allocated buffer. I am not sure why on glibc on linux this doesn't outright crash, but it does crash on my ARM phone. By initialising to NULL, getdelim correctly allocates a buffer for the data rather than reallocating a string literal. --- src/builtins.c | 4 ++-- src/main.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/builtins.c b/src/builtins.c index caf18c2..d6049f3 100644 --- a/src/builtins.c +++ b/src/builtins.c @@ -540,7 +540,7 @@ void stemfread(value_t *v) { eval_error("EMPTY STACK"); return; } - char *val = ""; + char *val = NULL; size_t len = 0; FILE *fp = fopen(v1->str_word->value, "rb"); if (!fp) { @@ -1341,7 +1341,7 @@ void include(value_t *v) { eval_error("EMPTY STACK"); return; } - char *val = ""; + char *val = NULL; size_t len = 0; string_t *strval = init_string("/usr/local/share/stem/stemlib/"); string_concat(strval, v1->str_word); diff --git a/src/main.c b/src/main.c index de0abe7..2a6ed6b 100644 --- a/src/main.c +++ b/src/main.c @@ -49,7 +49,7 @@ void sigint_handler(int signum) { int main(int argc, char **argv) { value_t *v; size_t len = 0; - char *buf = ""; + char *buf = NULL; /* Parsing arguments */ if (argc < 2) { -- cgit