Skip to content

Commit f4d0c3c

Browse files
committed
Adopt suggestion from @mikeash
1 parent e24b433 commit f4d0c3c

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

stdlib/public/runtime/MetadataLookup.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -474,10 +474,13 @@ static bool sameObjCTypeManglings(Demangle::NodePointer node1,
474474
#endif
475475

476476
/// Optimization for the case where we need to compare a StringRef and a null terminated C string
477-
/// Not converting s2 to a StringRef avoids the need to call both strlen and memcmp
477+
/// Not converting s2 to a StringRef avoids the need to call both strlen and memcmp when non-matching
478+
/// but equal length
478479
static bool stringRefEqualsCString(StringRef s1, const char *s2) {
479480
size_t length = s1.size();
480-
return strncmp(s1.data(), s2, length) == 0 && s2[length] == '\0';
481+
// It may be possible for s1 to contain embedded NULL characters
482+
// so additionally validate that the lengths match
483+
return strncmp(s1.data(), s2, length) == 0 && strlen(s2) == length;
481484
}
482485

483486
bool

0 commit comments

Comments
 (0)