From 1229f1ef3b82498af600965141cde29a3c928e29 Mon Sep 17 00:00:00 2001 From: David Neto Date: Tue, 10 Dec 2024 22:23:27 -0500 Subject: [PATCH] assembler: ensure progress when seeking the version string (#5910) When trying to parse SPIR-V version from assembly comments, ensure a match against an initial comment doesn't cause the scanner to go back to the beginning of the assembly text. Fixed: #5909 --- source/spirv_target_env.cpp | 2 +- test/target_env_test.cpp | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/source/spirv_target_env.cpp b/source/spirv_target_env.cpp index 8e1b2dd79c..d1172a060a 100644 --- a/source/spirv_target_env.cpp +++ b/source/spirv_target_env.cpp @@ -230,7 +230,7 @@ bool spvReadEnvironmentFromText(const std::vector& text, // If no match, determine whether the header has ended (in which case, // assumption has failed.) // Skip until the next line. - i = j; + i += j; for (; i < text.size(); ++i) { if (text[i] == '\n') break; } diff --git a/test/target_env_test.cpp b/test/target_env_test.cpp index faffa8a1e0..eb06a69136 100644 --- a/test/target_env_test.cpp +++ b/test/target_env_test.cpp @@ -221,6 +221,7 @@ INSTANTIATE_TEST_SUITE_P( {" \t ; Version: 1.1", true, SPV_ENV_UNIVERSAL_1_1}, // Previous lines {"; SPIR-V\n; Version: 1.1", true, SPV_ENV_UNIVERSAL_1_1}, + {"; -\n; SPIR-V\n; Version: 1.1", true, SPV_ENV_UNIVERSAL_1_1}, // After a non-header line {"OpCapability Shader\n; Version: 1.1", false, kSentinelEnv}}));