mirror of
https://github.com/neovim/neovim.git
synced 2025-09-28 14:08:32 +00:00
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:

committed by
Justin M. Keyes

parent
448dd2adfa
commit
72ad5a16e7
@@ -129,7 +129,10 @@ static inline khint_t String_hash(String s)
|
|||||||
|
|
||||||
static inline bool String_eq(String a, String b)
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user