[PATCH] cmd: Set errorlevel to 0 when 'call' is invoked with an empty string.
Aaron Hill
aa1ronham at gmail.com
Mon Oct 12 15:57:21 CDT 2020
Previously, invoking 'call' with an empty string would leave errorlevel
unchanged. Reset errorlevel to 0 to match the behavior of
the Windows 'cmd.exe'.
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=49982
Signed-off-by: Aaron Hill <aa1ronham at gmail.com>
---
programs/cmd/tests/test_builtins.cmd | 3 +++
programs/cmd/wcmdmain.c | 10 +++++++++-
2 files changed, 12 insertions(+), 1 deletion(-)
diff --git a/programs/cmd/tests/test_builtins.cmd b/programs/cmd/tests/test_builtins.cmd
index 73b0917c275..c7418b759e4 100644
--- a/programs/cmd/tests/test_builtins.cmd
+++ b/programs/cmd/tests/test_builtins.cmd
@@ -3149,6 +3149,9 @@ echo %ErrorLevel% should be 7
if errorlevel 7 echo setting var worked too well, bad
call :setError 3
echo %ErrorLevel% should still be 7
+rem Verify that (call ) sets errorlevel to 0
+(call )
+if errorlevel 1 echo errorlevel should have been 0
echo ------------ Testing GOTO ------------
if a==a goto dest1
diff --git a/programs/cmd/wcmdmain.c b/programs/cmd/wcmdmain.c
index 47e43fcd675..78f07b1b7b4 100644
--- a/programs/cmd/wcmdmain.c
+++ b/programs/cmd/wcmdmain.c
@@ -1041,6 +1041,7 @@ void WCMD_run_program (WCHAR *command, BOOL called)
WCHAR *lastSlash;
WCHAR pathext[MAXSTRING];
WCHAR *firstParam;
+ DWORD firstParamLen;
BOOL extensionsupplied = FALSE;
BOOL explicit_path = FALSE;
BOOL status;
@@ -1053,6 +1054,13 @@ void WCMD_run_program (WCHAR *command, BOOL called)
firstParam = WCMD_parameter(command, 0, NULL, FALSE, TRUE);
if (!firstParam) return;
+ firstParamLen = lstrlenW(firstParam);
+ if (firstParamLen == 0) {
+ // Windows sets errorlevel to 0 when invoking 'call' on an empty string
+ errorlevel = 0;
+ return;
+ }
+
/* Calculate the search path and stem to search for */
if (wcspbrk (firstParam, delims) == NULL) { /* No explicit path given, search path */
static const WCHAR curDir[] = {'.',';','\0'};
@@ -1063,7 +1071,7 @@ void WCMD_run_program (WCHAR *command, BOOL called)
lstrcpyW (pathtosearch, curDir);
}
if (wcschr(firstParam, '.') != NULL) extensionsupplied = TRUE;
- if (lstrlenW(firstParam) >= MAX_PATH)
+ if (firstParamLen >= MAX_PATH)
{
WCMD_output_asis_stderr(WCMD_LoadMessage(WCMD_LINETOOLONG));
return;
--
2.28.0
More information about the wine-devel
mailing list