From 80716d0787077fd8d9912bc60ce1eb5e2c9003b9 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 2 May 2016 19:22:57 +0200 Subject: [PATCH] fix key-upgrade function (coverity CID 102076) fix MSVC warning (strncpy) --- src/attributes/key.c | 10 ++++++---- src/util/log.test.c | 1 + 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/attributes/key.c b/src/attributes/key.c index 3df55174d..39c7dab66 100644 --- a/src/attributes/key.c +++ b/src/attributes/key.c @@ -71,10 +71,9 @@ void a_upgradekeys(attrib **alist, attrib *abegin) { int n = 0, *keys = 0; int i = 0, val[4]; attrib *a, *ak = a_find(*alist, &at_keys); - if (!ak) { - ak = a_add(alist, a_new(&at_keys)); + if (ak) { keys = (int *)ak->data.v; - n = keys ? keys[0] : 0; + if (keys) n = keys[0]; } for (a = abegin; a && a->type == abegin->type; a = a->next) { val[i++] = a->data.i; @@ -88,9 +87,12 @@ void a_upgradekeys(attrib **alist, attrib *abegin) { if (i > 0) { keys = realloc(keys, sizeof(int) * (n + i + 1)); memcpy(keys + n + 1, val, sizeof(int)*i); + if (!ak) { + ak = a_add(alist, a_new(&at_keys)); + } } + ak->data.v = keys; keys[0] = n + i; - a->data.v = keys; } attrib_type at_key = { diff --git a/src/util/log.test.c b/src/util/log.test.c index 7dbe65f74..e718d1193 100644 --- a/src/util/log.test.c +++ b/src/util/log.test.c @@ -1,3 +1,4 @@ +#include #include #include "log.h"