Fix overflow bug with MD_StringMatchFlag_RightSideSloppy

If a is longer than b, then MD_S8Match will check outside of b's bounds.
This commit is contained in:
Ben Visness
2021-12-31 12:52:39 -06:00
parent 7b2b00d8da
commit bda95a298a
+1 -1
View File
@@ -958,7 +958,7 @@ MD_S8Match(MD_String8 a, MD_String8 b, MD_MatchFlags flags)
if(a.size == b.size || flags & MD_StringMatchFlag_RightSideSloppy) if(a.size == b.size || flags & MD_StringMatchFlag_RightSideSloppy)
{ {
result = 1; result = 1;
for(MD_u64 i = 0; i < a.size; i += 1) for(MD_u64 i = 0; i < a.size && i < b.size; i += 1)
{ {
MD_b32 match = (a.str[i] == b.str[i]); MD_b32 match = (a.str[i] == b.str[i]);
if(flags & MD_StringMatchFlag_CaseInsensitive) if(flags & MD_StringMatchFlag_CaseInsensitive)