Skip to content

Commit 216b7db

Browse files
committed
Fix issue with non properly null terminated code strings
1 parent bb2a19b commit 216b7db

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

src/nbl/asset/utils/CGLSLCompiler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ core::smart_refctd_ptr<ICPUShader> CGLSLCompiler::compileToSPIRV(const char* cod
143143
return nullptr;
144144
}
145145

146-
auto newCode = preprocessShader(code, glslOptions.stage, glslOptions.preprocessorOptions);
146+
auto newCode = preprocessShader(std::string(code), glslOptions.stage, glslOptions.preprocessorOptions);
147147

148148
shaderc::Compiler comp;
149149
shaderc::CompileOptions shadercOptions; //default options

src/nbl/video/CVulkanLogicalDevice.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,13 @@ class CVulkanLogicalDevice final : public ILogicalDevice
526526
}
527527
else
528528
{
529+
const char* begin = static_cast<const char*>(source->getPointer());
530+
const char* end = begin + source->getSize();
531+
std::string code(begin, end);
532+
533+
auto newCodeBuffer = core::make_smart_refctd_ptr<asset::CDummyCPUBuffer>(code.size() + 1u, code.data(), core::adopt_memory);
534+
auto newCPUShader = core::make_smart_refctd_ptr<asset::ICPUShader>(std::move(newCodeBuffer), cpushader->getStage(), cpushader->getContentType(), std::string(cpushader->getFilepathHint()));
535+
529536
auto compiler = m_compilerSet->getShaderCompiler(cpushader->getContentType());
530537

531538
asset::IShaderCompiler::SCompilerOptions commonCompileOptions = {};
@@ -543,14 +550,14 @@ class CVulkanLogicalDevice final : public ILogicalDevice
543550
if (cpushader->getContentType() == asset::ICPUShader::E_CONTENT_TYPE::ECT_HLSL)
544551
{
545552
// TODO: add specific HLSLCompiler::SOption params
546-
spirvShader = m_compilerSet->compileToSPIRV(cpushader.get(), commonCompileOptions);
553+
spirvShader = m_compilerSet->compileToSPIRV(newCPUShader.get(), commonCompileOptions);
547554
}
548555
else if (cpushader->getContentType() == asset::ICPUShader::E_CONTENT_TYPE::ECT_GLSL)
549556
{
550-
spirvShader = m_compilerSet->compileToSPIRV(cpushader.get(), commonCompileOptions);
557+
spirvShader = m_compilerSet->compileToSPIRV(newCPUShader.get(), commonCompileOptions);
551558
}
552559
else
553-
spirvShader = m_compilerSet->compileToSPIRV(cpushader.get(), commonCompileOptions);
560+
spirvShader = m_compilerSet->compileToSPIRV(newCPUShader.get(), commonCompileOptions);
554561

555562
}
556563

0 commit comments

Comments
 (0)