From d619d58ccdae30298eb0ddadf415426c55c8dc80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nils=20O=2E=20Sel=C3=A5sdal?= Date: Tue, 1 Oct 2013 22:30:39 +0200 Subject: [PATCH] Fix overflow in strv_null_terminate, and don't make it increase .cnt --- src/strvec.c | 4 ++-- test/test_strv.c | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/strvec.c b/src/strvec.c index 9131b3f..7919ad5 100644 --- a/src/strvec.c +++ b/src/strvec.c @@ -29,7 +29,8 @@ int uc_strv_expand(struct UCStrv *strv) int rc = 0; if (strv->cnt >= strv->allocated) { - rc = uc_strv_grow(strv, 1); + //make some extra room + rc = uc_strv_grow(strv, 4); } return rc; @@ -81,7 +82,6 @@ int uc_strv_null_terminate(struct UCStrv *strv) } strv->strings[strv->cnt] = NULL; - strv->cnt++; return 0; } diff --git a/test/test_strv.c b/test/test_strv.c index e8bf8ec..3d172da 100644 --- a/test/test_strv.c +++ b/test/test_strv.c @@ -68,6 +68,7 @@ START_TEST (test_strv_null_terminate) rc = uc_strv_null_terminate(&strv); fail_if(rc != 0); + fail_if(strv.cnt != 1); //shouldn't increase .cnt fail_if(strv.strings[strv.cnt] != NULL); uc_strv_destroy(&strv);