l_strv_append() test and minor patch
cover l_strv_append() test and minor patch
The l_strv_append() function needlessly post-incremented an array index value prior to returning. Drop the post-increment, and a l_strv_append() unit test.
Ossama Othman (2):
unit: Add test for l_strv_append().
strv: Remove unnecessary post-increment.
ell/strv.c | 2 +- unit/test-string.c | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-)
Signature · 1 line
2.17.1
PATCH 1/2 unit: Add test for l_strv_append().
--- unit/test-string.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)
unit/test-string.c +19 -0
@@ -253,6 +253,24 @@ static void test_strv_contains(const void *test_data)assert (l_strv_contains (strv3,"Bar" ) == true); } +static void test_strv_append (const void *test_data) +{ +const char *src[] = {"Foo" ,"Bar" }; +char **dst =NULL ; + +size_t len =L_ARRAY_SIZE (src); + +for (size_t i =0 ; i < len; i++) + dst =l_strv_append (dst, src[i]); + +assert (l_strv_length (dst) == len); + +for (size_t i =0 ; i < len; i++) +assert (strcmp (src[i], dst[i]) ==0 ); + +l_strv_free (dst); +} +static void test_parse_args (const void *test_data) { static struct test_case {
@@ -319,6 +337,7 @@ int main(int argc, char *argv[])l_test_add ("strv_length" , test_strv_length,NULL );l_test_add ("strv_contains" , test_strv_contains,NULL ); +l_test_add ("strv_append" , test_strv_append,NULL );l_test_add ("parse_args" , test_parse_args,NULL );
Signature · 1 line
2.17.1
PATCH 2/2 strv: Remove unnecessary post-increment.
In reply to Ossama OthmanRemove unecessary post-increment of a string array index in l_strv_append(). The updated index value was not used after the post-increment.
--- ell/strv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
ell/strv.c +1 -1
@@ -284,7 +284,7 @@ LIB_EXPORT char **l_strv_append(char **str_array, const char *str)for (i =0 ; i < len; i++) ret[i] = str_array[i]; - ret[i++] =l_strdup (str); + ret[i] =l_strdup (str);l_free (str_array);
Signature · 1 line
2.17.1
Hi Ossama,
Quoted 4 lines · Ossama Othman
The
l_strv_append()function needlessly post-incremented an array index value prior to returning. Drop the post-increment, and al_strv_append()unit test.
Both applied, thanks.
Regards,
-Denis