From 708345d16a877ac164171439cf9b4ea825b78d23 Mon Sep 17 00:00:00 2001 From: kaizhangNV <149626564+kaizhangNV@users.noreply.github.com> Date: Wed, 8 May 2024 12:25:11 -0700 Subject: Fix crash in obfuscation (#4134) Slang crashes during obfuscation because of referencing the nullptr pointer. Add the checking. In addition, above situation happens when user provide an empty slang shader with '-obfuscate' option, we shouldn't do anything in that case. So add an early return in obfuscateModuleLocs if no IR code is actually generated. --- source/slang/slang-ir-obfuscate-loc.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'source') diff --git a/source/slang/slang-ir-obfuscate-loc.cpp b/source/slang/slang-ir-obfuscate-loc.cpp index 9aef6f6a6..79497e7a3 100644 --- a/source/slang/slang-ir-obfuscate-loc.cpp +++ b/source/slang/slang-ir-obfuscate-loc.cpp @@ -68,6 +68,11 @@ SlangResult obfuscateModuleLocs(IRModule* module, SourceManager* sourceManager) // Find all of the instructions with source locs _findInstsRec(module->getModuleInst(), instWithLocs); + if (instWithLocs.getCount() == 0) + { + // Nothing to do + return SLANG_OK; + } // Sort them instWithLocs.sort(); @@ -233,8 +238,8 @@ SlangResult obfuscateModuleLocs(IRModule* module, SourceManager* sourceManager) } // We can now just set all the new locs in the instructions + if(const LocPair* curPair = locPairs.getBuffer()) { - const LocPair* curPair = locPairs.getBuffer(); LocPair pair = *curPair; for (const auto& instWithLoc : instWithLocs) -- cgit v1.2.3