From 551838cea217e3d9df11dcaea52c42b02449de91 Mon Sep 17 00:00:00 2001 From: NHOrus Date: Fri, 7 Jul 2017 11:21:37 +0300 Subject: [PATCH] Deal around newline-only lines pruned to zero-lenght Test for that, too --- misc.c | 15 +++++++++++++-- tests/barehands.chk | 4 ++++ tests/barehands.log | 3 ++- tests/illformed.chk | 6 ++++++ tests/illformed.log | 1 + 5 files changed, 26 insertions(+), 3 deletions(-) diff --git a/misc.c b/misc.c index 784eb73..cef3651 100644 --- a/misc.c +++ b/misc.c @@ -352,7 +352,7 @@ char* get_input() bool silent_yes() { - bool outcome; + bool outcome = false; for (;;) { char* reply = get_input(); @@ -363,6 +363,11 @@ bool silent_yes() exit(EXIT_SUCCESS); // LCOV_EXCL_STOP } + if (strlen(reply) == 0) { + free(reply); + rspeak(PLEASE_ANSWER); + continue; + } char* firstword = (char*) xmalloc(strlen(reply) + 1); sscanf(reply, "%s", firstword); @@ -398,7 +403,7 @@ bool yes(const char* question, const char* yes_response, const char* no_response /* Print message X, wait for yes/no answer. If yes, print Y and return true; * if no, print Z and return false. */ { - bool outcome; + bool outcome = false; for (;;) { speak(question); @@ -412,6 +417,12 @@ bool yes(const char* question, const char* yes_response, const char* no_response // LCOV_EXCL_STOP } + if (strlen(reply) == 0) { + free(reply); + rspeak(PLEASE_ANSWER); + continue; + } + char* firstword = (char*) xmalloc(strlen(reply) + 1); sscanf(reply, "%s", firstword); diff --git a/tests/barehands.chk b/tests/barehands.chk index 09ddeda..1c94758 100644 --- a/tests/barehands.chk +++ b/tests/barehands.chk @@ -273,6 +273,10 @@ With what? Your bare hands? Please answer the question. +> green + +Please answer the question. + > n The dragon looks rather nasty. You'd best not try to get by. diff --git a/tests/barehands.log b/tests/barehands.log index 9f9c408..72fc3de 100644 --- a/tests/barehands.log +++ b/tests/barehands.log @@ -50,7 +50,8 @@ drop bird extinguish dragon kill dragon +green n kill dragon y -kill dragon \ No newline at end of file +kill dragon diff --git a/tests/illformed.chk b/tests/illformed.chk index 1a118f2..73ca685 100644 --- a/tests/illformed.chk +++ b/tests/illformed.chk @@ -7,6 +7,12 @@ Please answer the question. Welcome to Adventure!! Would you like instructions? +> + +Please answer the question. + +Welcome to Adventure!! Would you like instructions? + > y Somewhere nearby is Colossal Cave, where others have found fortunes in diff --git a/tests/illformed.log b/tests/illformed.log index 5e56b4a..13821c4 100644 --- a/tests/illformed.log +++ b/tests/illformed.log @@ -1,5 +1,6 @@ ## Test for various cases not found in walkthroughs. foo + y seed 1801426495 version -- 2.31.1