fix key-upgrade function (coverity CID 102076)

fix MSVC warning (strncpy)
This commit is contained in:
Enno Rehling 2016-05-02 19:22:57 +02:00
parent c4d31d368e
commit 80716d0787
2 changed files with 7 additions and 4 deletions

View File

@ -71,10 +71,9 @@ void a_upgradekeys(attrib **alist, attrib *abegin) {
int n = 0, *keys = 0; int n = 0, *keys = 0;
int i = 0, val[4]; int i = 0, val[4];
attrib *a, *ak = a_find(*alist, &at_keys); attrib *a, *ak = a_find(*alist, &at_keys);
if (!ak) { if (ak) {
ak = a_add(alist, a_new(&at_keys));
keys = (int *)ak->data.v; 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) { for (a = abegin; a && a->type == abegin->type; a = a->next) {
val[i++] = a->data.i; val[i++] = a->data.i;
@ -88,9 +87,12 @@ void a_upgradekeys(attrib **alist, attrib *abegin) {
if (i > 0) { if (i > 0) {
keys = realloc(keys, sizeof(int) * (n + i + 1)); keys = realloc(keys, sizeof(int) * (n + i + 1));
memcpy(keys + n + 1, val, sizeof(int)*i); 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; keys[0] = n + i;
a->data.v = keys;
} }
attrib_type at_key = { attrib_type at_key = {

View File

@ -1,3 +1,4 @@
#include <platform.h>
#include <CuTest.h> #include <CuTest.h>
#include "log.h" #include "log.h"