mirror of
https://github.com/RPCSX/SPIRV-Tools.git
synced 2025-01-27 06:11:47 +00:00
advance() should check current string index is in bound.
This commit is contained in:
parent
9042f40f7c
commit
8f6ba14b58
@ -78,6 +78,7 @@ spv_result_t advanceLine(spv_text text, spv_position position) {
|
||||
/// @return result code
|
||||
spv_result_t advance(spv_text text, spv_position position) {
|
||||
// NOTE: Consume white space, otherwise don't advance.
|
||||
if (position->index >= text->length) return SPV_END_OF_STREAM;
|
||||
switch (text->str[position->index]) {
|
||||
case '\0':
|
||||
return SPV_END_OF_STREAM;
|
||||
|
@ -88,4 +88,12 @@ TEST(TextAdvance, NullTerminator) {
|
||||
ASSERT_EQ(SPV_END_OF_STREAM, data.advance());
|
||||
}
|
||||
|
||||
TEST(TextAdvance, NoNullTerminator) {
|
||||
spv_text_t text = {"OpNop\nSomething else in memory", 6};
|
||||
AssemblyContext data(&text, nullptr);
|
||||
const spv_position_t line_break = {1, 5, 5};
|
||||
data.setPosition(line_break);
|
||||
ASSERT_EQ(SPV_END_OF_STREAM, data.advance());
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
|
Loading…
x
Reference in New Issue
Block a user