From 1bdb67b2c3c574abe283bafd54d24042de270762 Mon Sep 17 00:00:00 2001 From: Patryk Obara Date: Fri, 27 Dec 2019 15:46:28 +0100 Subject: [PATCH] Add an assert in 'choice' command Static analyzer indicates that in this context `rem` can be NULL, therefore should not be passed to strchr, but in this context `rem` cannot be NULL becasuse `args` is not NULL (even after StripSpaces). --- src/shell/shell_cmds.cpp | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/shell/shell_cmds.cpp b/src/shell/shell_cmds.cpp index 017ee750..4993b1b0 100644 --- a/src/shell/shell_cmds.cpp +++ b/src/shell/shell_cmds.cpp @@ -16,22 +16,23 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ - -#include "dosbox.h" #include "shell.h" + +#include +#include +#include +#include +#include +#include +#include +#include + #include "callback.h" #include "regs.h" #include "bios.h" #include "../dos/drives.h" #include "support.h" #include "control.h" -#include -#include -#include -#include -#include -#include -#include static SHELL_Cmd cmd_list[]={ { "DIR", 0, &DOS_Shell::CMD_DIR, "SHELL_CMD_DIR_HELP"}, @@ -1329,7 +1330,10 @@ void DOS_Shell::CMD_CHOICE(char * args){ WriteOut(MSG_Get("SHELL_ILLEGAL_SWITCH"),rem); return; } - if (args == rem) args = strchr(rem,0)+1; + if (args == rem) { + assert(args); + args = strchr(rem, '\0') + 1; + } if (rem) rem += 2; if(rem && rem[0]==':') rem++; /* optional : after /c */ if (args > last) args = NULL;