Skip to content

Commit 4d415f6

Browse files
aleino-nvcsyonghe
andauthoredFeb 28, 2025
Fix a bug where Session::parseCommandLineArguments returns invalid data (#6461)
This helps to address issue #4760. Co-authored-by: Yong He <yonghe@outlook.com>
1 parent 96f1962 commit 4d415f6

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed
 

‎source/slang/slang.cpp

+6-4
Original file line numberDiff line numberDiff line change
@@ -1108,17 +1108,19 @@ SLANG_NO_THROW SlangResult SLANG_MCALL Session::parseCommandLineArguments(
11081108
if (outDesc->structureSize < sizeof(slang::SessionDesc))
11091109
return SLANG_E_BUFFER_TOO_SMALL;
11101110
RefPtr<ParsedCommandLineData> outData = new ParsedCommandLineData();
1111-
SerializedOptionsData optionData;
11121111
RefPtr<EndToEndCompileRequest> tempReq = new EndToEndCompileRequest(this);
11131112
tempReq->processCommandLineArguments(argv, argc);
1113+
outData->options.setCount(1 + tempReq->getLinkage()->targets.getCount());
1114+
int optionDataIndex = 0;
1115+
SerializedOptionsData& optionData = outData->options[optionDataIndex];
1116+
optionDataIndex++;
11141117
tempReq->getOptionSet().serialize(&optionData);
1115-
outData->options.add(optionData);
11161118
for (auto target : tempReq->getLinkage()->targets)
11171119
{
11181120
slang::TargetDesc tdesc;
1119-
SerializedOptionsData targetOptionData;
1121+
SerializedOptionsData& targetOptionData = outData->options[optionDataIndex];
1122+
optionDataIndex++;
11201123
tempReq->getTargetOptionSet(target).serialize(&targetOptionData);
1121-
outData->options.add(targetOptionData);
11221124
tdesc.compilerOptionEntryCount = (uint32_t)targetOptionData.entries.getCount();
11231125
tdesc.compilerOptionEntries = targetOptionData.entries.getBuffer();
11241126
outData->targets.add(tdesc);

0 commit comments

Comments
 (0)