From: Lyndon Nerenberg Date: Thu, 10 Apr 2014 10:52:17 +0000 (-0700) Subject: If getln() sees a newline as its first character, it incorrectly X-Git-Url: https://diplodocus.org/git/nmh/commitdiff_plain/d2afe7d6749bc73f88e1fea993de2e0dbb5b3565?ds=sidebyside;hp=d4288570b9513c706907deb882ec6a15e218d0e3 If getln() sees a newline as its first character, it incorrectly references a character one byte before the start of its input buffer. --- diff --git a/uip/prompter.c b/uip/prompter.c index 37f5960b..b43d0c74 100644 --- a/uip/prompter.c +++ b/uip/prompter.c @@ -329,6 +329,7 @@ getln (char *buffer, int n) { int c; char *cp; + static int quoting = 0; cp = buffer; *cp = 0; @@ -350,12 +351,13 @@ getln (char *buffer, int n) for (;;) { switch (c = getchar ()) { case EOF: + quoting = 0; clearerr (stdin); longjmp (sigenv, DONE); case '\n': - if (cp[-1] == QUOTE) { - cp[-1] = c; + if (quoting) { + *(cp - 1) = c; wtuser = 0; return 1; } @@ -365,6 +367,11 @@ getln (char *buffer, int n) return 0; default: + if (c == QUOTE) { + quoting = 1; + } else { + quoting = 0; + } if (cp < buffer + n) *cp++ = c; *cp = 0;