diff options
author | Daniel <steew0x8@protonmail.com> | 2021-11-07 19:41:49 +0100 |
---|---|---|
committer | Daniel <steew0x8@protonmail.com> | 2021-11-07 19:41:49 +0100 |
commit | fa22526b8477b30fb50e6019fd0248f18964c788 (patch) | |
tree | 11cbbd887b17af3d3c747f828285a3743750109b | |
parent | ce8ff29507ca5772c4ef4b023fa676f6701d61e0 (diff) | |
download | rpncalc-fa22526b8477b30fb50e6019fd0248f18964c788.tar.gz |
fix segfault on EOF
-rw-r--r-- | main.c | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/main.c b/main.c index c8b10e6..2b79001 100644 --- a/main.c +++ b/main.c @@ -37,7 +37,8 @@ int main() { fprintf(s.defout, s.prompt, s.command_count, s.last_op); s.last_op = 0; char *endptr = NULL; - fgets(buf, BUF_SIZE, s.defbuf); + char *check = fgets(buf, BUF_SIZE, s.defbuf); + if (check == NULL) exit(0); buf[strcspn(buf, "\n")] = 0; double interpreted = strtod(buf, &endptr); if (errno == ERANGE) { |