From: Richard Russon Date: Sun, 26 May 2019 15:02:24 +0000 (+0100) Subject: test: improve test_mutt_str_substr_cpy() X-Git-Tag: 2019-10-25~187^2~2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a2925fd03048bdf1ff0015276f7ac96285158358;p=neomutt test: improve test_mutt_str_substr_cpy() --- diff --git a/mutt/string.c b/mutt/string.c index c6d7ad01e..92a0aa7ec 100644 --- a/mutt/string.c +++ b/mutt/string.c @@ -549,7 +549,7 @@ const char *mutt_str_strchrnul(const char *s, char c) /** * mutt_str_substr_cpy - Copy a sub-string into a buffer * @param dest Buffer for the result - * @param begin Start of the string to copy + * @param begin Start of the string to copy * @param end End of the string to copy * @param destlen Length of buffer * @retval ptr Destination buffer diff --git a/test/string/mutt_str_substr_cpy.c b/test/string/mutt_str_substr_cpy.c index c0d685988..aa003122e 100644 --- a/test/string/mutt_str_substr_cpy.c +++ b/test/string/mutt_str_substr_cpy.c @@ -29,7 +29,7 @@ void test_mutt_str_substr_cpy(void) { // char *mutt_str_substr_cpy(char *dest, const char *begin, const char *end, size_t destlen); - const char *str = "apple banana"; + const char *str = "apple banana\0xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; { TEST_CHECK(mutt_str_substr_cpy(NULL, str + 3, str + 7, 32) == NULL); @@ -44,4 +44,27 @@ void test_mutt_str_substr_cpy(void) char buf[32] = { 0 }; TEST_CHECK(mutt_str_substr_cpy(buf, str + 3, NULL, sizeof(buf)) == buf); } + + { + char buf[32] = { 0 }; + TEST_CHECK(mutt_str_substr_cpy(buf, str + 3, str + 7, 0) == buf); + } + + { + char buf[32] = { 0 }; + TEST_CHECK(mutt_str_substr_cpy(buf, str + 3, str + 3, sizeof(buf)) == buf); + TEST_CHECK(strcmp(buf, "") == 0); + } + + { + char buf[32] = { 0 }; + TEST_CHECK(mutt_str_substr_cpy(buf, str + 3, str + 7, sizeof(buf)) == buf); + TEST_CHECK(strcmp(buf, "le b") == 0); + } + + { + char buf[32] = { 0 }; + TEST_CHECK(mutt_str_substr_cpy(buf, str + 3, str + 64, sizeof(buf)) == buf); + TEST_CHECK(strcmp(buf, "le banana") == 0); + } }