Exit client with 'q' fix bounds check - sacc - sacc(omys), simple console gopher client
git clone git://bitreich.org/sacc/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/sacc/
Log
Files
Refs
Tags
LICENSE
---
commit 79e35daca2237ca69767574fbcb29192acf1c9ef
parent e831853d549fee7311b1d02c320dbfa174e115b1
Author: Quentin Rameau 
Date:   Tue, 20 Jun 2017 19:55:58 +0200

Exit client with 'q' fix bounds check

Diffstat:
  M sacc.c                              |      13 ++++++++++---

1 file changed, 10 insertions(+), 3 deletions(-)
---
diff --git a/sacc.c b/sacc.c
@@ -358,6 +358,7 @@ int
 main(int argc, char *argv[])
 {
         Item *hole;
+        char buf[BUFSIZ];
         int n, itm;
 
         if (argc != 2)
@@ -370,10 +371,16 @@ main(int argc, char *argv[])
                 if (!(n = display(hole)))
                         break;
                 do {
-                        printf("%d items, visit (empty to quit): ", n);
-                        if (scanf("%d", &itm) != 1)
+                        printf("%d items, visit (^D or q: quit): ", n);
+                        if (!fgets(buf, sizeof(buf), stdin)) {
+                                putchar('\n');
                                 goto quit;
-                } while (itm < 1 && itm > n);
+                        }
+                        if (!strcmp(buf, "q\n"))
+                                goto quit;
+                        if (sscanf(buf, "%d", &itm) != 1)
+                                continue;
+                } while (itm < 1 || itm > n);
                 hole = ((Item **)hole->target)[itm-1];
         }