From db90d1a4c2260d1604d32778705c5b8a52808449 Mon Sep 17 00:00:00 2001 From: Krystine Sherwin <93062060+KrystalDelusion@users.noreply.github.com> Date: Sat, 17 Aug 2024 11:33:29 +1200 Subject: [PATCH] logcmd.cc: Check length before unquoting `log "` should log `"`. Also fix test script to correctly fail when more than one test fails. --- passes/cmds/logcmd.cc | 2 +- tests/scripts/test_logging.sh | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/passes/cmds/logcmd.cc b/passes/cmds/logcmd.cc index 52f6b1e31..c6cba1115 100644 --- a/passes/cmds/logcmd.cc +++ b/passes/cmds/logcmd.cc @@ -97,7 +97,7 @@ struct LogPass : public Pass { text += args[argidx] + ' '; if (!text.empty()) text.resize(text.size()-1); - if (text[0] == '"' && text[text.size()-1] == '"') + if (text.size() > 1 && text[0] == '"' && text[text.size()-1] == '"') text = text.substr(1, text.size()-2); const char *fmtline = newline ? "%s\n" : "%s"; diff --git a/tests/scripts/test_logging.sh b/tests/scripts/test_logging.sh index d69fcc752..d2f635f76 100755 --- a/tests/scripts/test_logging.sh +++ b/tests/scripts/test_logging.sh @@ -31,7 +31,10 @@ test_log "\"!bang\"" "!bang" test_log "\"spaces are cool too\"" "spaces are cool too" test_log "\"log a\"; log b" "log a" test_log "\"log a\"; log b" "b" +test_log "\"" "\"" +test_log "\\\"" "\\\\\"" #\" == \" -if [ -f quotes-*.err ] ; then +errors=( quotes-*.err ) +if [ -f $errors ] ; then exit 1 fi