diff options
| author | 2022-01-17 12:45:34 +0300 | |
|---|---|---|
| committer | 2022-01-17 21:50:51 +0300 | |
| commit | a943600019969ce0382821e7ee19ef4b990564cb (patch) | |
| tree | f22d5f6a2b385e1e45b824ccdab8e137207d6198 /src/shader_recompiler/backend/glsl | |
| parent | Merge pull request #7719 from gidoly/patch-6 (diff) | |
| download | yuzu-a943600019969ce0382821e7ee19ef4b990564cb.tar.gz yuzu-a943600019969ce0382821e7ee19ef4b990564cb.tar.xz yuzu-a943600019969ce0382821e7ee19ef4b990564cb.zip | |
shader_recompiler: fix potential OOB access
Found by static analysis with PVS-Studio. Original check wasn't actually checking for OOB and would segfault in case of it.
Diffstat (limited to 'src/shader_recompiler/backend/glsl')
| -rw-r--r-- | src/shader_recompiler/backend/glsl/glsl_emit_context.cpp | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/src/shader_recompiler/backend/glsl/glsl_emit_context.cpp b/src/shader_recompiler/backend/glsl/glsl_emit_context.cpp index bb7f1a0fd..e816a93ec 100644 --- a/src/shader_recompiler/backend/glsl/glsl_emit_context.cpp +++ b/src/shader_recompiler/backend/glsl/glsl_emit_context.cpp | |||
| @@ -458,9 +458,10 @@ void EmitContext::DefineGenericOutput(size_t index, u32 invocations) { | |||
| 458 | std::string definition{fmt::format("layout(location={}", index)}; | 458 | std::string definition{fmt::format("layout(location={}", index)}; |
| 459 | const u32 remainder{4 - element}; | 459 | const u32 remainder{4 - element}; |
| 460 | const TransformFeedbackVarying* xfb_varying{}; | 460 | const TransformFeedbackVarying* xfb_varying{}; |
| 461 | if (!runtime_info.xfb_varyings.empty()) { | 461 | const size_t xfb_varying_index{base_index + element}; |
| 462 | xfb_varying = &runtime_info.xfb_varyings[base_index + element]; | 462 | if (xfb_varying_index < runtime_info.xfb_varyings.size()) { |
| 463 | xfb_varying = xfb_varying && xfb_varying->components > 0 ? xfb_varying : nullptr; | 463 | xfb_varying = &runtime_info.xfb_varyings[xfb_varying_index]; |
| 464 | xfb_varying = xfb_varying->components > 0 ? xfb_varying : nullptr; | ||
| 464 | } | 465 | } |
| 465 | const u32 num_components{xfb_varying ? xfb_varying->components : remainder}; | 466 | const u32 num_components{xfb_varying ? xfb_varying->components : remainder}; |
| 466 | if (element > 0) { | 467 | if (element > 0) { |