slash

slash is a simple type-oriented programming language
Log | Files | Refs | README | LICENSE

commit bfed49ae6902cd426b248f777da69cefa7d7f848
parent 40b42f71c5030cce7816ffb03e6c8c5319103caf
Author: Mario Rosell R. Martinez <mario@mariorosell.es>
Date:   Sat,  4 Apr 2026 21:00:58 +0200

mem: don't memfault on missing file

fclose()'ing a file twice returns in a memfault, so now if you open an
unexistent file, then it does not memfault after perror()'ing

Diffstat:
Mpipeline.c | 21++++++++++++---------
1 file changed, 12 insertions(+), 9 deletions(-)

diff --git a/pipeline.c b/pipeline.c @@ -29,20 +29,21 @@ lex(void) { tok_t tk; + if (!stat.i_fstream) return; + /* 1. init */ lex_init(); /* 2. lup */ do { tk = nexttok(); - - /* debug: can be removed: - * puts(tokname(t.type)); - * if (tk.type == TOK_IDENT) - * printf("(%s)", t.lexeme); - * - * printf("\n"); - */ + + /* debug: can be removed */ + puts(tokname(tk.type)); + if (tk.type == TOK_IDENT) + printf("(%s)", tk.lexeme); + printf("\n"); + (void)tk; } while (tk.type != TOK_EOF); } @@ -50,7 +51,9 @@ lex(void) static void end(void) { - fclose(stat.i_fstream); /* don't leave the fd open */ + if (stat.i_fstream) { + fclose(stat.i_fstream); /* don't leave the fd open */ + } } void