mirror of
https://github.com/neovim/neovim.git
synced 2024-12-20 03:05:11 -07: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:
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)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user