summaryrefslogtreecommitdiff
path: root/tests/core/string.c
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2021-08-31 15:22:44 -0400
committerEdward Thomson <ethomson@edwardthomson.com>2021-09-01 20:39:51 -0400
commit1196de4f263bdbb02c2c5b7030f159c2ff23af34 (patch)
tree32122f00dfc1082abf55d8875154e1425ed6cefa /tests/core/string.c
parente5a3277452095a908787c3ea0279fbec21c0a76a (diff)
downloadlibgit2-1196de4f263bdbb02c2c5b7030f159c2ff23af34.tar.gz
util: introduce `git__strlcmp`
Introduce a utility function that compares a NUL terminated string to a possibly not-NUL terminated string with length. This is similar to `strncmp` but with an added check to ensure that the lengths match (not just the `size` portion of the two strings).
Diffstat (limited to 'tests/core/string.c')
-rw-r--r--tests/core/string.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/tests/core/string.c b/tests/core/string.c
index 85db0c662..928dfbcc1 100644
--- a/tests/core/string.c
+++ b/tests/core/string.c
@@ -123,3 +123,14 @@ void test_core_string__strcasecmp(void)
cl_assert(git__strcasecmp("et", "e\342\202\254ghi=") < 0);
cl_assert(git__strcasecmp("\303\215", "\303\255") < 0);
}
+
+void test_core_string__strlcmp(void)
+{
+ const char foo[3] = { 'f', 'o', 'o' };
+
+ cl_assert(git__strlcmp("foo", "foo", 3) == 0);
+ cl_assert(git__strlcmp("foo", foo, 3) == 0);
+ cl_assert(git__strlcmp("foo", "foobar", 3) == 0);
+ cl_assert(git__strlcmp("foobar", "foo", 3) > 0);
+ cl_assert(git__strlcmp("foo", "foobar", 6) < 0);
+}