about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorDaniel <steew0x8@protonmail.com>2021-11-07 19:41:49 +0100
committerDaniel <steew0x8@protonmail.com>2021-11-07 19:41:49 +0100
commitfa22526b8477b30fb50e6019fd0248f18964c788 (patch)
tree11cbbd887b17af3d3c747f828285a3743750109b
parentce8ff29507ca5772c4ef4b023fa676f6701d61e0 (diff)
downloadrpncalc-fa22526b8477b30fb50e6019fd0248f18964c788.tar.gz
fix segfault on EOF
-rw-r--r--main.c3
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) {