[PATCH 0/1] MR10309: vbscript: fix Split function to handle empty strings and null values
From: Francis De Brabandere <francisdb@gmail.com> --- dlls/vbscript/global.c | 13 +++++++++++++ dlls/vbscript/tests/api.vbs | 4 ++++ 2 files changed, 17 insertions(+) diff --git a/dlls/vbscript/global.c b/dlls/vbscript/global.c index 965a6233bc2..8315ec6f17b 100644 --- a/dlls/vbscript/global.c +++ b/dlls/vbscript/global.c @@ -2761,6 +2761,18 @@ static HRESULT Global_Split(BuiltinDisp *This, VARIANT *args, unsigned args_cnt, start = 0; len = SysStringLen(string); + + if(!len) { + bounds.lLbound = 0; + bounds.cElements = 0; + sa = SafeArrayCreate(VT_VARIANT, 1, &bounds); + if(!sa) { + hres = E_OUTOFMEMORY; + goto error; + } + goto done; + } + count = 0; indices = malloc( indices_max * sizeof(int)); @@ -2823,6 +2835,7 @@ static HRESULT Global_Split(BuiltinDisp *This, VARIANT *args, unsigned args_cnt, } SafeArrayUnaccessData(sa); +done: error: if(SUCCEEDED(hres) && res) { V_VT(res) = VT_ARRAY|VT_VARIANT; diff --git a/dlls/vbscript/tests/api.vbs b/dlls/vbscript/tests/api.vbs index 319ef90e70f..e18d887306b 100644 --- a/dlls/vbscript/tests/api.vbs +++ b/dlls/vbscript/tests/api.vbs @@ -830,6 +830,10 @@ Call ok(x(2) = "def", "Split(""abc--def"",""-"")(2)=" & x(2)) x = Split("abcdefghi","def") Call ok(x(0) = "abc", "Split(""abcdefghi"",""def"")(0)=" & x(0)) Call ok(x(1) = "ghi", "Split(""abcdefghi"",""def"")(1)=" & x(1)) +x = Split("", ",") +Call ok(UBound(x) = -1, "UBound(Split("""","",""))=" & UBound(x)) +x = Split("") +Call ok(UBound(x) = -1, "UBound(Split(""""))=" & UBound(x)) x = Split("12345",3) Call ok(x(0) = "12", "Split(""12345"",3)(0)=" & x(0)) Call ok(x(1) = "45", "Split(""12345"",3)(1)=" & x(1)) -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/10309
Jacek Caban (@jacek) commented about dlls/vbscript/global.c:
start = 0;
len = SysStringLen(string); + + if(!len) { + bounds.lLbound = 0; + bounds.cElements = 0; + sa = SafeArrayCreate(VT_VARIANT, 1, &bounds); + if(!sa) { + hres = E_OUTOFMEMORY; + goto error;
This goto is redundant, "goto done" in the following statement already handles that case. Also, instead of creating two identical labels, please rename the existing one. Could you also update the commit message to follow the Wine style guidelines? The subject should start with a capitalized "Split" and end with a period. When referencing Bugzilla, please use the "Wine-Bug: " tag. See git log for examples. -- https://gitlab.winehq.org/wine/wine/-/merge_requests/10309#note_131981
On Thu Mar 12 13:27:29 2026 +0000, Jacek Caban wrote:
This goto is redundant, "goto done" in the following statement already handles that case. Also, instead of creating two identical labels, please rename the existing one. Could you also update the commit message to follow the Wine style guidelines? The subject should start with a capitalized "Split" and end with a period. When referencing Bugzilla, please use the "Wine-Bug: " tag. See git log for examples. A google for "Wine style guidelines" makes me thirsty :-)
found it: https://gitlab.winehq.org/wine/wine/-/wikis/Submitting-Patches#the-commit-me... -- https://gitlab.winehq.org/wine/wine/-/merge_requests/10309#note_131985
participants (3)
-
Francis De Brabandere -
Francis De Brabandere (@francisdb) -
Jacek Caban (@jacek)