From 5e435a7c0bf1087e2e147209f2bf4739cb853545 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 8 Dec 2017 19:26:26 +0100 Subject: [PATCH 1/2] pass cppcheck v 1.54 default checks --- s/travis-build | 11 +++++------ src/kernel/item.c | 10 ++++++---- src/kernel/pool.c | 4 ++-- src/kernel/unit.c | 11 +++++++---- 4 files changed, 20 insertions(+), 16 deletions(-) diff --git a/s/travis-build b/s/travis-build index 2da3ed7b5..6b14e8848 100755 --- a/s/travis-build +++ b/s/travis-build @@ -19,13 +19,12 @@ cd tests set -e [ -z $BUILD ] && BUILD=Debug ; export BUILD s/cmake-init -s/build -cd $ROOT -inifile cppcheck --version cppcheck --quiet --error-exitcode=1 src +s/build +cd process +make +cd $ROOT +inifile s/runtests -V integration_tests -cd ../process -make - diff --git a/src/kernel/item.c b/src/kernel/item.c index 9d750cb2f..b2a35669a 100644 --- a/src/kernel/item.c +++ b/src/kernel/item.c @@ -746,11 +746,13 @@ void init_resources(void) int get_money(const unit * u) { const struct resource_type *rtype = get_resourcetype(R_SILVER); - const item *i = u->items; - while (i && i->type->rtype != rtype) { - i = i->next; + const item *i; + for (i = u->items; i; i = i->next) { + if (i->type->rtype == rtype) { + return i->number; + } } - return i ? i->number : 0; + return 0; } int set_money(unit * u, int v) diff --git a/src/kernel/pool.c b/src/kernel/pool.c index d85846f64..e58bc131e 100644 --- a/src/kernel/pool.c +++ b/src/kernel/pool.c @@ -114,7 +114,7 @@ int change_reservation(unit * u, const item_type * itype, int value) res->type = itype; res->value = value; } - else if (res && res->value + value <= 0) { + else if (res->value + value <= 0) { *rp = res->next; free(res); return 0; @@ -139,7 +139,7 @@ int set_resvalue(unit * u, const item_type * itype, int value) res->type = itype; res->value = value; } - else if (res && value <= 0) { + else if (value <= 0) { *rp = res->next; free(res); return 0; diff --git a/src/kernel/unit.c b/src/kernel/unit.c index 2e3dab804..cb42071b0 100644 --- a/src/kernel/unit.c +++ b/src/kernel/unit.c @@ -394,11 +394,14 @@ faction *dfindhash(int no) } #else struct faction *dfindhash(int no) { - unit *u = deleted_units; - while (u && u->no != no) { - u = u->next; + unit *u; + + for (u = deleted_units; u; u = u->next) { + if (u->no == no) { + return u->faction; + } } - return u ? u->faction : NULL; + return NULL; } #endif From 1b9a686101057bab275900510d9091c8070228fb Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 8 Dec 2017 20:17:40 +0100 Subject: [PATCH 2/2] fix berkeley size/ulen error remove weather module (unused) --- conf/eressea.ini | 1 - src/battle.c | 3 +- src/kernel/db/berkeley.c | 6 +- src/modules/CMakeLists.txt | 1 - src/modules/weather.c | 132 ------------------------------------- src/modules/weather.h | 54 --------------- src/triggers/shock.c | 2 +- 7 files changed, 6 insertions(+), 193 deletions(-) delete mode 100644 src/modules/weather.c delete mode 100644 src/modules/weather.h diff --git a/conf/eressea.ini b/conf/eressea.ini index aed9c219c..17547f8f9 100644 --- a/conf/eressea.ini +++ b/conf/eressea.ini @@ -4,7 +4,6 @@ sender = Eressea Server name = Eressea report = reports verbose = 0 -lomem = 0 memcheck = 0 locales = de,en diff --git a/src/battle.c b/src/battle.c index 7f70eaa4a..602fd2ca2 100644 --- a/src/battle.c +++ b/src/battle.c @@ -1009,7 +1009,7 @@ int natural_armor(unit * du) static int rc_specialdamage(const unit *au, const unit *du, const struct weapon_type *wtype) { const race *ar = u_race(au); - int m, modifier = 0; + int modifier = 0; if (wtype != NULL) { if (fval(u_race(du), RCF_DRAGON)) { static int cache; @@ -1022,6 +1022,7 @@ static int rc_specialdamage(const unit *au, const unit *du, const struct weapon_ } } if (wtype->modifiers != NULL) { + int m; for (m = 0; wtype->modifiers[m].value; ++m) { /* weapon damage for this weapon, possibly by race */ if (wtype->modifiers[m].flags & WMF_DAMAGE) { diff --git a/src/kernel/db/berkeley.c b/src/kernel/db/berkeley.c index 5a65ee3b0..c16a6d13a 100644 --- a/src/kernel/db/berkeley.c +++ b/src/kernel/db/berkeley.c @@ -41,10 +41,10 @@ int db_driver_order_save(struct order_data *od) assert(od && od->_str); key.data = &recno; - key.size = sizeof(recno); + key.size = key.ulen = sizeof(recno); key.flags = DB_DBT_USERMEM; data.data = (void *)od->_str; - data.size = strlen(od->_str) + 1; + data.size = data.ulen = strlen(od->_str) + 1; data.flags = DB_DBT_USERMEM; ret = g_dbp->put(g_dbp, NULL, &key, &data, DB_APPEND); assert(ret == 0); @@ -63,7 +63,7 @@ struct order_data *db_driver_order_load(int id) memset(&data, 0, sizeof(DBT)); recno = (db_recno_t)id; key.data = &recno; - key.size = sizeof(recno); + key.size = key.ulen = sizeof(recno); key.flags = DB_DBT_USERMEM; ret = g_dbp->get(g_dbp, NULL, &key, &data, 0); if (ret == 0) { diff --git a/src/modules/CMakeLists.txt b/src/modules/CMakeLists.txt index 82dee9ec4..5b98897d4 100644 --- a/src/modules/CMakeLists.txt +++ b/src/modules/CMakeLists.txt @@ -4,7 +4,6 @@ autoseed.c gmcmd.c museum.c score.c -weather.c xmas.c ) FOREACH(_FILE ${_FILES}) diff --git a/src/modules/weather.c b/src/modules/weather.c deleted file mode 100644 index ef71197b0..000000000 --- a/src/modules/weather.c +++ /dev/null @@ -1,132 +0,0 @@ -/* -Copyright (c) 1998-2015, Enno Rehling -Katja Zedel - -Permission to use, copy, modify, and/or distribute this software for any -purpose with or without fee is hereby granted, provided that the above -copyright notice and this permission notice appear in all copies. - -THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -**/ - -#ifdef WEATHER - -#include -#include -#include "weather.h" - -/* libc includes */ -#include - -weather *create_weather(region * r, weather_t type) -{ - weather *w; - - w = calloc(1, sizeof(weather)); - w->center[0] = r->x; - w->center[1] = r->y; - w->type = type; - w->move[0] = (rng_int() % 3) - 1; - w->move[1] = (rng_int() % 3) - 1; - - switch (type) { - case WEATHER_STORM: - w->radius = rng_int() % 2 + 1; - break; - case WEATHER_HURRICANE: - w->radius = 1; - break; - default: - w->radius = 0; - } - - addlist(&weathers, w); - - return w; -} - -double distance(int x1, int y1, int x2, int y2) -{ - return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); -} - -/* Diese Funktion ermittelt für jede Region, welches Wetter in ihr - herrscht. Die Wettertypen sind dabei nach ihrer Reihenfolge in der - enumeration priorisiert. - - - Einladen - set_weather(); - - Eigentliche Auswertung - - Veränderungen des Wetters - set_weather(); - - Report generieren - - Abspeichern - - Diese Routine ist sehr rechenaufwendig! - */ - -void set_weather(void) -{ - weather_t i; - weather *w; - short x, y; - int d; - region *r; - - for (r = regions; r; r = r->next) { - r->weathertype = WEATHER_NONE; - } - - for (i = 0; i < MAXWEATHERS; i++) { - for (w = weathers; w; w = w->next) { - if (w->type == i) { - for (x = w->center[0] - w->radius; x <= w->center[0] + w->radius; x++) { - for (y = w->center[1] - w->radius; y <= w->center[1] + w->radius; y++) { - d = distance(w->center[0], w->center[1], x, y); - if (floor(d + 0.5) <= w->radius) { - r = findregion(x, y); - if (r) { - r->weathertype = w->type; - } - } - } - } - } - } - } -} - -void move_weather(void) -{ - weather *w, *wnext; - region *r; - - for (w = weathers; w;) { - wnext = w->next; - w->center[0] = w->center[0] + w->move[0]; - w->center[1] = w->center[1] + w->move[1]; - r = findregion(w->center[0], w->center[1]); - if (!r || rng_int() % 100 < 5) { - removelist(&weathers, w); - } - w = wnext; - } -} - -#else -#include -static const char *copyright = "(c) Eressea PBEM 2000"; - -void init_weather(void) -{ - fputs(copyright, stderr); - /* TODO: Initialization */ -} -#endif diff --git a/src/modules/weather.h b/src/modules/weather.h deleted file mode 100644 index 812f31ee7..000000000 --- a/src/modules/weather.h +++ /dev/null @@ -1,54 +0,0 @@ -/* -Copyright (c) 1998-2015, Enno Rehling - Katja Zedel - -Permission to use, copy, modify, and/or distribute this software for any -purpose with or without fee is hereby granted, provided that the above -copyright notice and this permission notice appear in all copies. - -THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -**/ - -#ifndef H_MOD_WEATHER_H -#define H_MOD_WEATHER_H -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef WEATHER -# error "the weather system is disabled" -#endif - - enum { - WEATHER_NONE, - WEATHER_STORM, - WEATHER_HURRICANE, - MAXWEATHERS - }; - - typedef unsigned char weather_t; - - typedef struct weather { - struct weather *next; - weather_t type; /* Typ der Wetterzone */ - int center[2]; /* Koordinaten des Zentrums */ - int radius; - int move[2]; - } weather; - - weather *weathers; - - void set_weather(void); - void move_weather(void); - -#ifdef __cplusplus -} -#endif -#endif diff --git a/src/triggers/shock.c b/src/triggers/shock.c index ca4ad67df..690a115df 100644 --- a/src/triggers/shock.c +++ b/src/triggers/shock.c @@ -19,7 +19,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include "shock.h" -#include "magic.h" +#include /* kernel includes */ #include