Fix String_eq() (#5051)

Change implementation to compare sequences of bytes instead of C
strings.

The former implementation would return "false positives" in these cases:

"\0a" and "\0b": C strings are NUL-terminated, so it would compare two
                 empty strings.

"a" and "ab":    If both strings aren't the same length, it would
                 compare only up to the length of the shorter one.

Fixes #5046.
This commit is contained in:
Marco Hinz 2016-07-13 04:16:43 +02:00 committed by Justin M. Keyes
parent 448dd2adfa
commit 72ad5a16e7

View File

@ -129,7 +129,10 @@ static inline khint_t String_hash(String s)
static inline bool String_eq(String a, String b)
{
return strncmp(a.data, b.data, MIN(a.size, b.size)) == 0;
if (a.size != b.size) {
return false;
}
return memcmp(a.data, b.data, a.size) == 0;
}