Skip to content

Commit 90b0e14

Browse files
authored
fix #13968: Addon execution fails for some paths with spaces on Windows (danmar#7632)
1 parent f4eb733 commit 90b0e14

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

cli/cppcheckexecutor.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -712,9 +712,10 @@ int CppCheckExecutor::executeCommand(std::string exe, std::vector<std::string> a
712712
joinedArgs += arg;
713713
}
714714

715-
const std::string cmd = exe + " " + joinedArgs + " " + redirect;
715+
std::string cmd = exe + " " + joinedArgs + " " + redirect;
716716

717717
#ifdef _WIN32
718+
cmd = "\"" + cmd + "\"";
718719
FILE* p = _popen(cmd.c_str(), "r");
719720
#else
720721
FILE *p = popen(cmd.c_str(), "r");

test/cli/other_test.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,35 @@ def test_execute_addon_failure_json_notexist(tmpdir):
243243
assert stderr == "{}:0:0: error: Bailing out from analysis: Checking file failed: Failed to execute addon 'addon.json' - exitcode is {} [internalError]\n\n^\n".format(test_file, ec)
244244

245245

246+
@pytest.mark.skipif(sys.platform != "win32", reason="Windows specific issue")
247+
def test_execute_addon_path_with_spaces(tmpdir):
248+
addon_json = os.path.join(tmpdir, 'addon.json')
249+
addon_dir = os.path.join(tmpdir, 'A Folder')
250+
addon_script = os.path.join(addon_dir, 'addon.bat')
251+
252+
with open(addon_json, 'wt') as f:
253+
f.write(json.dumps({'executable': addon_script }))
254+
255+
os.makedirs(addon_dir, exist_ok=True)
256+
257+
with open(addon_script, 'wt') as f:
258+
f.write('@echo {"file":"1.c","linenr":1,"column":1,"severity":"error","message":"hello world","errorId":"hello","addon":"test"}')
259+
260+
test_file = os.path.join(tmpdir, 'test.cpp')
261+
with open(test_file, 'wt') as f:
262+
pass
263+
264+
args = [
265+
'--addon={}'.format(addon_json),
266+
test_file,
267+
]
268+
269+
_, _, stderr = cppcheck(args)
270+
271+
# Make sure the full command is used
272+
assert '1.c:1:1: error: hello world [test-hello]\n' in stderr
273+
274+
246275
def test_execute_addon_failure_json_ctu_notexist(tmpdir):
247276
# specify non-existent python executable so execution of addon fails
248277
addon_json = os.path.join(tmpdir, 'addon.json')

0 commit comments

Comments
 (0)