aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarco Hinz <mh.codebro@gmail.com>2016-07-13 04:16:43 +0200
committerJustin M. Keyes <justinkz@gmail.com>2016-07-12 22:16:43 -0400
commit72ad5a16e734062046965023726791e0e35a50be (patch)
tree50483c39215f8e92d159be8b7494828bca3ceab6
parent448dd2adfa48b1b1a7dd4c5d0bb377dc09dbbd0d (diff)
downloadrneovim-72ad5a16e734062046965023726791e0e35a50be.tar.gz
rneovim-72ad5a16e734062046965023726791e0e35a50be.tar.bz2
rneovim-72ad5a16e734062046965023726791e0e35a50be.zip
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.
-rw-r--r--src/nvim/map.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/nvim/map.c b/src/nvim/map.c
index 03439e7a9c..398e74268f 100644
--- a/src/nvim/map.c
+++ b/src/nvim/map.c
@@ -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;
}