sacc

sacc (saccomys): simple gopher client.
Log | Files | Refs | LICENSE

commit 1c1721cdc446ead866ee31a5ad88e544a8ab338b
parent 97d775439105379413694efa4783c6b2f86169dc
Author: Quentin Rameau <quinq@fifth.space>
Date:   Tue, 20 Jun 2017 19:55:58 +0200

Exit client with 'q' fix bounds check

Diffstat:
sacc.c | 13++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/sacc.c b/sacc.c @@ -363,6 +363,7 @@ int main(int argc, char *argv[]) { Item *hole; + char buf[BUFSIZ]; int n, itm; if (argc != 2) @@ -375,10 +376,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]; }