The issue was noticed in a project that contains SPIRV-Cross as a static library and has _HAS_EXCEPTIONS set to 0.
Currently, Microsoft STL doesn't copy the exception message if _HAS_EXCEPTIONS=0 (see https://github.com/microsoft/STL/issues/2114). Because of that passing a temporary string object to std::exception constructor would lead to an invalid pointer being saved.
This issue affects SPIRV-Cross (if SPIRV_CROSS_EXCEPTIONS_TO_ASSERTIONS is not used) because CompilerError only has one version of a constructor that accepts const std::string&, but I only found const char* being passed to it in SPIRV-Cross codebase, so a temporary std::string is created on each SPIRV_CROSS_THROW invocation.
Here's a minimal example to reproduce (Tested in Visual Studio Community 17.7.4).
Hi!
The issue was noticed in a project that contains SPIRV-Cross as a static library and has
_HAS_EXCEPTIONS
set to 0. Currently, Microsoft STL doesn't copy the exception message if_HAS_EXCEPTIONS
=0 (see https://github.com/microsoft/STL/issues/2114). Because of that passing a temporary string object tostd::exception
constructor would lead to an invalid pointer being saved. This issue affects SPIRV-Cross (ifSPIRV_CROSS_EXCEPTIONS_TO_ASSERTIONS
is not used) becauseCompilerError
only has one version of a constructor that acceptsconst std::string&
, but I only foundconst char*
being passed to it in SPIRV-Cross codebase, so a temporarystd::string
is created on eachSPIRV_CROSS_THROW
invocation.Here's a minimal example to reproduce (Tested in Visual Studio Community 17.7.4).