From 4d415f6af2266cc38798d72f6816c60b91a5003c Mon Sep 17 00:00:00 2001 From: Anders Leino Date: Fri, 28 Feb 2025 03:58:07 +0200 Subject: Fix a bug where Session::parseCommandLineArguments returns invalid data (#6461) This helps to address issue #4760. Co-authored-by: Yong He --- source/slang/slang.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp index 001354162..cd8cabfe5 100644 --- a/source/slang/slang.cpp +++ b/source/slang/slang.cpp @@ -1108,17 +1108,19 @@ SLANG_NO_THROW SlangResult SLANG_MCALL Session::parseCommandLineArguments( if (outDesc->structureSize < sizeof(slang::SessionDesc)) return SLANG_E_BUFFER_TOO_SMALL; RefPtr outData = new ParsedCommandLineData(); - SerializedOptionsData optionData; RefPtr tempReq = new EndToEndCompileRequest(this); tempReq->processCommandLineArguments(argv, argc); + outData->options.setCount(1 + tempReq->getLinkage()->targets.getCount()); + int optionDataIndex = 0; + SerializedOptionsData& optionData = outData->options[optionDataIndex]; + optionDataIndex++; tempReq->getOptionSet().serialize(&optionData); - outData->options.add(optionData); for (auto target : tempReq->getLinkage()->targets) { slang::TargetDesc tdesc; - SerializedOptionsData targetOptionData; + SerializedOptionsData& targetOptionData = outData->options[optionDataIndex]; + optionDataIndex++; tempReq->getTargetOptionSet(target).serialize(&targetOptionData); - outData->options.add(targetOptionData); tdesc.compilerOptionEntryCount = (uint32_t)targetOptionData.entries.getCount(); tdesc.compilerOptionEntries = targetOptionData.entries.getBuffer(); outData->targets.add(tdesc); -- cgit v1.2.3