From f2b0ba1ec60e23e1e813ce4a86e650860dcdbc35 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 12 Oct 2015 18:59:15 +0200 Subject: [PATCH 1/6] eliminate find_spell warning for games where nobody is cursed, and you cannot summon igjarjuk --- src/battle.c | 2 +- src/kernel/spell.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/battle.c b/src/battle.c index a47db8163..319aa4151 100644 --- a/src/battle.c +++ b/src/battle.c @@ -1691,7 +1691,7 @@ void do_combatmagic(battle * b, combatmagic_t was) if (was == DO_PRECOMBATSPELL) { for (s = b->sides; s != b->sides + b->nsides; ++s) { fighter *fig = 0; - if (fval(s->faction, FFL_CURSED) && s->bf->attacker) { + if (s->bf->attacker && fval(s->faction, FFL_CURSED)) { spell *sp = find_spell("igjarjuk"); if (sp) { int si; diff --git a/src/kernel/spell.c b/src/kernel/spell.c index 6b161fc99..05e1ab8e8 100644 --- a/src/kernel/spell.c +++ b/src/kernel/spell.c @@ -113,7 +113,7 @@ spell *find_spell(const char *name) cb_get_kv(match, &sp, sizeof(sp)); } else { - log_warning("find_spell: could not find spell '%s'\n", name); + log_debug("find_spell: could not find spell '%s'\n", name); } return sp; } From 8ee83fd500307065127ad9ca5cc8e72fb7e87806 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Thu, 22 Oct 2015 20:55:19 +0200 Subject: [PATCH 2/6] try adding coverity scan --- .travis.yml | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/.travis.yml b/.travis.yml index 003fb67ad..3586024a6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,19 +1,33 @@ sudo: false language: c compiler: - - gcc - - clang +- gcc +- clang script: s/travis-build addons: apt: packages: - - liblua5.2-dev - - libncurses5-dev - - libsqlite3-dev - - libxml2-dev - - valgrind + - liblua5.2-dev + - libncurses5-dev + - libsqlite3-dev + - libxml2-dev + - valgrind os: - - linux +- linux notifications: slack: secure: F89aXLWaE125PaJIlETv12jT4EfH6wLXJmGCPZzrN3OcLn2ahDWqjwuzR7lOEDf2nAISmeMPyDZMhEHXLNHAE5qP6lg9yliYQw5hzGmDK9m1xUq/pPEne/b2Y7K3my1mkRZ6n3asbHgSmBWAfCIk1JN8R5Rv+rmbLuWLc+zofts= +env: + global: + secure: SOuZkWHfQmKf7qCVkK8WSsTU7R9f2nJYh1tMFdiauVKfdOSqYZwoPomp9S+7cPZhGrYEZ91mPadrWGTD/02c+tXVOJA51JGzvM55kl8Dy1htqHt7thCjAr1cDRh/Ek+qLGGf4CwAlzO/xnSUCttvioT8F678HJgArwqnR6i3Mgc= + +addons: + coverity_scan: + project: + name: "eressea/server" + description: "Eressea PBEM server" + notification_email: enno.rehling@gmail.com + build_command: s/travis-build + branch_pattern: coverity_scan +# build_command_prepend: "" + From 61cee2606b6d8247a73f2ad3c79825dace67331b Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Thu, 22 Oct 2015 21:01:46 +0200 Subject: [PATCH 3/6] Revert "try adding coverity scan" This reverts commit 86fea3723b2550c0f93563bd76969c387c53f5c5. --- .travis.yml | 30 ++++++++---------------------- 1 file changed, 8 insertions(+), 22 deletions(-) diff --git a/.travis.yml b/.travis.yml index 3586024a6..003fb67ad 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,33 +1,19 @@ sudo: false language: c compiler: -- gcc -- clang + - gcc + - clang script: s/travis-build addons: apt: packages: - - liblua5.2-dev - - libncurses5-dev - - libsqlite3-dev - - libxml2-dev - - valgrind + - liblua5.2-dev + - libncurses5-dev + - libsqlite3-dev + - libxml2-dev + - valgrind os: -- linux + - linux notifications: slack: secure: F89aXLWaE125PaJIlETv12jT4EfH6wLXJmGCPZzrN3OcLn2ahDWqjwuzR7lOEDf2nAISmeMPyDZMhEHXLNHAE5qP6lg9yliYQw5hzGmDK9m1xUq/pPEne/b2Y7K3my1mkRZ6n3asbHgSmBWAfCIk1JN8R5Rv+rmbLuWLc+zofts= -env: - global: - secure: SOuZkWHfQmKf7qCVkK8WSsTU7R9f2nJYh1tMFdiauVKfdOSqYZwoPomp9S+7cPZhGrYEZ91mPadrWGTD/02c+tXVOJA51JGzvM55kl8Dy1htqHt7thCjAr1cDRh/Ek+qLGGf4CwAlzO/xnSUCttvioT8F678HJgArwqnR6i3Mgc= - -addons: - coverity_scan: - project: - name: "eressea/server" - description: "Eressea PBEM server" - notification_email: enno.rehling@gmail.com - build_command: s/travis-build - branch_pattern: coverity_scan -# build_command_prepend: "" - From e23a7fc87ddc7c160a3425d85a1bca410922acba Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Tue, 27 Oct 2015 12:32:32 +0100 Subject: [PATCH 4/6] deprecate report_kampfstatus and implement a replacement function. --- s/build | 7 +++++-- s/cmake-init | 2 +- s/install | 1 + src/reports.c | 20 ++++++++++++++------ src/reports.h | 4 +++- src/spy.c | 2 +- 6 files changed, 25 insertions(+), 11 deletions(-) diff --git a/s/build b/s/build index 3f193a7bd..ea0f5f3d0 100755 --- a/s/build +++ b/s/build @@ -4,7 +4,6 @@ while [ ! -d $ROOT/.git ]; do ROOT=`dirname $ROOT` done -[ -z "$CC" ] && CC=clang [ -z "$BUILD" ] && BUILD=Debug [ -z "$JOBS" ] && [ "" != "which nproc" ] && JOBS=`nproc` @@ -14,11 +13,15 @@ JOBS=`distcc -j` if [ -z "$JOBS" ] ; then JOBS=1 elif [ $JOBS -gt 1 ] ; then +[ -z "$CC" ] && [ ! -z `which clang` ] && CC="clang" +[ -z "$CC" ] && [ ! -z `which gcc` ] && CC="gcc" +[ -z "$CC" ] && [ ! -z `which tcc` ] && CC="tcc" +[ -z "$CC" ] && [ ! -z `which cc` ] && CC="cc" CC="$DISTCC $CC" MAKEOPTS=-j$JOBS fi fi -echo "Building with CC=$CC and $JOBS jobs" +echo "Building with $JOBS jobs" if [ ! -d $ROOT/$BUILD ]; then echo "cannot find build directory $BUILD in $ROOT. did you run cmake-init?" diff --git a/s/cmake-init b/s/cmake-init index 3a8408b1a..05bae5540 100755 --- a/s/cmake-init +++ b/s/cmake-init @@ -10,7 +10,7 @@ done [ -z $BUILD ] && BUILD=Debug MACHINE=`uname -m` -[ -z "$CC" ] && [ ! -z `which gcc` ] && CC="clang" +[ -z "$CC" ] && [ ! -z `which clang` ] && CC="clang" [ -z "$CC" ] && [ ! -z `which gcc` ] && CC="gcc" [ -z "$CC" ] && [ ! -z `which tcc` ] && CC="tcc" [ -z "$CC" ] && [ ! -z `which cc` ] && CC="cc" diff --git a/s/install b/s/install index 31b94052d..5daa7cbc9 100755 --- a/s/install +++ b/s/install @@ -11,6 +11,7 @@ done DEST=$(dirname $ROOT)/server MACHINE=`uname -m` +[ -z "$CC" ] && [ ! -z `which clang` ] && CC="clang" [ -z "$CC" ] && [ ! -z `which gcc` ] && CC="gcc" [ -z "$CC" ] && [ ! -z `which tcc` ] && CC="tcc" [ -z "$CC" ] && [ ! -z `which cc` ] && CC="cc" diff --git a/src/reports.c b/src/reports.c index f09344ee1..7eff766c5 100644 --- a/src/reports.c +++ b/src/reports.c @@ -120,29 +120,36 @@ const char *combatstatus[] = { "status_avoid", "status_flee" }; -const char *report_kampfstatus(const unit * u, const struct locale *lang) +size_t report_status(const unit * u, const struct locale *lang, char *fsbuf, size_t buflen) { - static char fsbuf[64]; // FIXME: static return value const char * status = LOC(lang, combatstatus[u->status]); + size_t len = 0; if (!status) { const char *lname = locale_name(lang); struct locale *wloc = get_or_create_locale(lname); log_error("no translation for combat status %s in %s", combatstatus[u->status], lname); locale_setstring(wloc, combatstatus[u->status], combatstatus[u->status]); - strlcpy(fsbuf, combatstatus[u->status], sizeof(fsbuf)); + len = strlcpy(fsbuf, combatstatus[u->status], buflen); } else { - strlcpy(fsbuf, status, sizeof(fsbuf)); + len = strlcpy(fsbuf, status, buflen); } if (fval(u, UFL_NOAID)) { - strcat(fsbuf, ", "); - strcat(fsbuf, LOC(lang, "status_noaid")); + len += strlcat(fsbuf+len, ", ", buflen-len); + len += strlcat(fsbuf+len, LOC(lang, "status_noaid"), buflen-len); } + return len; +} + +const char * report_kampfstatus(const unit * u, const struct locale *lang) { + static char fsbuf[64]; // FIXME: static variable. + report_status(u, lang, fsbuf, sizeof(fsbuf)); return fsbuf; } + const char *hp_status(const unit * u) { double p; @@ -564,6 +571,7 @@ size_t size) const char *c = hp_status(u); c = c ? LOC(f->locale, c) : 0; bufp = STRLCPY(bufp, ", ", size); + // FIXME: use report_status bufp = STRLCPY(bufp, report_kampfstatus(u, f->locale), size); if (c || fval(u, UFL_HUNGER)) { bufp = STRLCPY(bufp, " (", size); diff --git a/src/reports.h b/src/reports.h index 2b3f9d51d..3af4b4035 100644 --- a/src/reports.h +++ b/src/reports.h @@ -85,8 +85,10 @@ extern "C" { const char *trailinto(const struct region *r, const struct locale *lang); + size_t report_status(const struct unit *u, + const struct locale *lang, char *buf, size_t siz); const char *report_kampfstatus(const struct unit *u, - const struct locale *lang); + const struct locale *lang); // FIXME: kill this (static variable) void register_reports(void); diff --git a/src/spy.c b/src/spy.c index 7343213c9..572f362df 100644 --- a/src/spy.c +++ b/src/spy.c @@ -59,7 +59,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * Spionage des Spions */ void spy_message(int spy, const unit * u, const unit * target) { - const char *str = report_kampfstatus(target, u->faction->locale); + const char *str = report_kampfstatus(target, u->faction->locale); // FIXME: use report_status instead ADDMSG(&u->faction->msgs, msg_message("spyreport", "spy target status", u, target, str)); From e3572ef14e74f5f1d8c56ea8f707a9cbaf6f4956 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Tue, 27 Oct 2015 12:36:11 +0100 Subject: [PATCH 5/6] eliminate deprecated call --- src/reports.h | 2 -- src/spy.c | 6 ++++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/reports.h b/src/reports.h index 3af4b4035..2c71803c3 100644 --- a/src/reports.h +++ b/src/reports.h @@ -87,8 +87,6 @@ extern "C" { const struct locale *lang); size_t report_status(const struct unit *u, const struct locale *lang, char *buf, size_t siz); - const char *report_kampfstatus(const struct unit *u, - const struct locale *lang); // FIXME: kill this (static variable) void register_reports(void); diff --git a/src/spy.c b/src/spy.c index 572f362df..eeca4e1d1 100644 --- a/src/spy.c +++ b/src/spy.c @@ -59,10 +59,12 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * Spionage des Spions */ void spy_message(int spy, const unit * u, const unit * target) { - const char *str = report_kampfstatus(target, u->faction->locale); // FIXME: use report_status instead + char status[32]; + + report_status(target, u->faction->locale, status, sizeof(status)); ADDMSG(&u->faction->msgs, msg_message("spyreport", "spy target status", u, - target, str)); + target, status)); if (spy > 20) { sc_mage *mage = get_mage(target); /* for mages, spells and magic school */ From feb915fe4ac3198532ba85b247247005a1d459bf Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Tue, 27 Oct 2015 12:37:52 +0100 Subject: [PATCH 6/6] eliminate deprecated reporting function, static variable --- src/reports.c | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/src/reports.c b/src/reports.c index 7eff766c5..ce66d273f 100644 --- a/src/reports.c +++ b/src/reports.c @@ -143,13 +143,6 @@ size_t report_status(const unit * u, const struct locale *lang, char *fsbuf, siz return len; } -const char * report_kampfstatus(const unit * u, const struct locale *lang) { - static char fsbuf[64]; // FIXME: static variable. - report_status(u, lang, fsbuf, sizeof(fsbuf)); - return fsbuf; -} - - const char *hp_status(const unit * u) { double p; @@ -571,8 +564,7 @@ size_t size) const char *c = hp_status(u); c = c ? LOC(f->locale, c) : 0; bufp = STRLCPY(bufp, ", ", size); - // FIXME: use report_status - bufp = STRLCPY(bufp, report_kampfstatus(u, f->locale), size); + bufp += report_status(u, f->locale, bufp, size); if (c || fval(u, UFL_HUNGER)) { bufp = STRLCPY(bufp, " (", size); if (c) {