All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] l_strv_append() test and minor patch
@ 2019-02-14 20:45 Ossama Othman
  2019-02-14 20:45 ` [PATCH 1/2] unit: Add test for l_strv_append() Ossama Othman
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Ossama Othman @ 2019-02-14 20:45 UTC (permalink / raw)
  To: ell

[-- Attachment #1: Type: text/plain, Size: 410 bytes --]

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(-)

-- 
2.17.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/2] unit: Add test for l_strv_append().
  2019-02-14 20:45 [PATCH 0/2] l_strv_append() test and minor patch Ossama Othman
@ 2019-02-14 20:45 ` Ossama Othman
  2019-02-14 20:45 ` [PATCH 2/2] strv: Remove unnecessary post-increment Ossama Othman
  2019-02-18  2:41 ` [PATCH 0/2] l_strv_append() test and minor patch Denis Kenzior
  2 siblings, 0 replies; 4+ messages in thread
From: Ossama Othman @ 2019-02-14 20:45 UTC (permalink / raw)
  To: ell

[-- Attachment #1: Type: text/plain, Size: 1135 bytes --]

---
 unit/test-string.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/unit/test-string.c b/unit/test-string.c
index c59a35f..710617b 100644
--- a/unit/test-string.c
+++ b/unit/test-string.c
@@ -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);
 
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] strv: Remove unnecessary post-increment.
  2019-02-14 20:45 [PATCH 0/2] l_strv_append() test and minor patch Ossama Othman
  2019-02-14 20:45 ` [PATCH 1/2] unit: Add test for l_strv_append() Ossama Othman
@ 2019-02-14 20:45 ` Ossama Othman
  2019-02-18  2:41 ` [PATCH 0/2] l_strv_append() test and minor patch Denis Kenzior
  2 siblings, 0 replies; 4+ messages in thread
From: Ossama Othman @ 2019-02-14 20:45 UTC (permalink / raw)
  To: ell

[-- Attachment #1: Type: text/plain, Size: 570 bytes --]

Remove 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(-)

diff --git a/ell/strv.c b/ell/strv.c
index a507626..89f2df5 100644
--- a/ell/strv.c
+++ b/ell/strv.c
@@ -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);
 
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 0/2] l_strv_append() test and minor patch
  2019-02-14 20:45 [PATCH 0/2] l_strv_append() test and minor patch Ossama Othman
  2019-02-14 20:45 ` [PATCH 1/2] unit: Add test for l_strv_append() Ossama Othman
  2019-02-14 20:45 ` [PATCH 2/2] strv: Remove unnecessary post-increment Ossama Othman
@ 2019-02-18  2:41 ` Denis Kenzior
  2 siblings, 0 replies; 4+ messages in thread
From: Denis Kenzior @ 2019-02-18  2:41 UTC (permalink / raw)
  To: ell

[-- Attachment #1: Type: text/plain, Size: 277 bytes --]

Hi Ossama,

On 02/14/2019 02:45 PM, Ossama Othman wrote:
> 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.
> 

Both applied, thanks.

Regards,
-Denis


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-02-18  2:41 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-14 20:45 [PATCH 0/2] l_strv_append() test and minor patch Ossama Othman
2019-02-14 20:45 ` [PATCH 1/2] unit: Add test for l_strv_append() Ossama Othman
2019-02-14 20:45 ` [PATCH 2/2] strv: Remove unnecessary post-increment Ossama Othman
2019-02-18  2:41 ` [PATCH 0/2] l_strv_append() test and minor patch Denis Kenzior

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.