From 72ad5a16e734062046965023726791e0e35a50be Mon Sep 17 00:00:00 2001 From: Marco Hinz Date: Wed, 13 Jul 2016 04:16:43 +0200 Subject: 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. --- src/nvim/map.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/nvim/map.c') 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; } -- cgit