Merge pull request #508 from ennorehling/develop

fix key-upgrade function (coverity CID 102076)
This commit is contained in:
Enno Rehling 2016-05-07 15:20:42 +02:00
commit 741804d98d
3 changed files with 8 additions and 5 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

@ -123,7 +123,7 @@ static void update_faction(sqlite3 *db, const faction *f) {
"INSERT INTO faction_data (faction_id, code, name, email, lang, turn)" "INSERT INTO faction_data (faction_id, code, name, email, lang, turn)"
" VALUES (?, ?, ?, ?, ?, ?)"; " VALUES (?, ?, ?, ?, ?, ?)";
sqlite3_stmt *stmt = 0; sqlite3_stmt *stmt = 0;
strncpy(code, itoa36(f->no), sizeof(code)); strcpy(code, itoa36(f->no));
sqlite3_prepare_v2(db, sql, -1, &stmt, 0); sqlite3_prepare_v2(db, sql, -1, &stmt, 0);
sqlite3_bind_int(stmt, 1, f->subscription); sqlite3_bind_int(stmt, 1, f->subscription);
sqlite3_bind_text(stmt, 2, code, -1, SQLITE_STATIC); sqlite3_bind_text(stmt, 2, code, -1, SQLITE_STATIC);

View File

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