forked from github/server
Merge pull request #366 from ennorehling/coverity-scans
Fix more coverity scan issues
This commit is contained in:
commit
a6039c7611
5 changed files with 33 additions and 33 deletions
|
@ -361,10 +361,10 @@ static int cr_race(variant var, char *buffer, const void *userdata)
|
||||||
static int cr_alliance(variant var, char *buffer, const void *userdata)
|
static int cr_alliance(variant var, char *buffer, const void *userdata)
|
||||||
{
|
{
|
||||||
const alliance *al = (const alliance *)var.v;
|
const alliance *al = (const alliance *)var.v;
|
||||||
|
unused_arg(userdata);
|
||||||
if (al != NULL) {
|
if (al != NULL) {
|
||||||
sprintf(buffer, "%d", al->id);
|
sprintf(buffer, "%d", al->id);
|
||||||
}
|
}
|
||||||
unused_arg(userdata);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -372,6 +372,7 @@ static int cr_skill(variant var, char *buffer, const void *userdata)
|
||||||
{
|
{
|
||||||
const faction *report = (const faction *)userdata;
|
const faction *report = (const faction *)userdata;
|
||||||
skill_t sk = (skill_t)var.i;
|
skill_t sk = (skill_t)var.i;
|
||||||
|
unused_arg(userdata);
|
||||||
if (sk != NOSKILL)
|
if (sk != NOSKILL)
|
||||||
sprintf(buffer, "\"%s\"",
|
sprintf(buffer, "\"%s\"",
|
||||||
translate(mkname("skill", skillnames[sk]), skillname(sk,
|
translate(mkname("skill", skillnames[sk]), skillname(sk,
|
||||||
|
@ -384,6 +385,7 @@ static int cr_skill(variant var, char *buffer, const void *userdata)
|
||||||
static int cr_order(variant var, char *buffer, const void *userdata)
|
static int cr_order(variant var, char *buffer, const void *userdata)
|
||||||
{
|
{
|
||||||
order *ord = (order *)var.v;
|
order *ord = (order *)var.v;
|
||||||
|
unused_arg(userdata);
|
||||||
if (ord != NULL) {
|
if (ord != NULL) {
|
||||||
char cmd[ORDERSIZE];
|
char cmd[ORDERSIZE];
|
||||||
char *wp = buffer;
|
char *wp = buffer;
|
||||||
|
@ -393,13 +395,11 @@ static int cr_order(variant var, char *buffer, const void *userdata)
|
||||||
|
|
||||||
*wp++ = '\"';
|
*wp++ = '\"';
|
||||||
for (rp = cmd; *rp;) {
|
for (rp = cmd; *rp;) {
|
||||||
switch (*rp) {
|
char r = *rp++;
|
||||||
case '\"':
|
if (r == '\"' || r == '\\') {
|
||||||
case '\\':
|
|
||||||
*wp++ = '\\';
|
*wp++ = '\\';
|
||||||
default:
|
|
||||||
*wp++ = *rp++;
|
|
||||||
}
|
}
|
||||||
|
*wp++ = r;
|
||||||
}
|
}
|
||||||
*wp++ = '\"';
|
*wp++ = '\"';
|
||||||
*wp++ = 0;
|
*wp++ = 0;
|
||||||
|
|
|
@ -165,8 +165,8 @@ struct order *ord)
|
||||||
else if (n == 0) {
|
else if (n == 0) {
|
||||||
int reserve = get_reservation(src, itype);
|
int reserve = get_reservation(src, itype);
|
||||||
if (reserve) {
|
if (reserve) {
|
||||||
msg_feedback(src, ord, "nogive_reserved", "resource reservation",
|
ADDMSG(&src->faction->msgs, msg_feedback(src, ord, "nogive_reserved", "resource reservation",
|
||||||
itype->rtype, reserve);
|
itype->rtype, reserve));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
error = 36;
|
error = 36;
|
||||||
|
@ -403,7 +403,7 @@ void give_unit(unit * u, unit * u2, order * ord)
|
||||||
int maxt = max_transfers();
|
int maxt = max_transfers();
|
||||||
|
|
||||||
assert(u);
|
assert(u);
|
||||||
if (!rule_transfermen() && u->faction != u2->faction) {
|
if (!rule_transfermen() && u2 && u->faction != u2->faction) {
|
||||||
cmistake(u, ord, 74, MSG_COMMERCE);
|
cmistake(u, ord, 74, MSG_COMMERCE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -618,8 +618,6 @@ void give_cmd(unit * u, order * ord)
|
||||||
* item-liste der unit, darum continue vor pointerumsetzten */
|
* item-liste der unit, darum continue vor pointerumsetzten */
|
||||||
if (give_item(itm->number, itm->type, u, u2, ord) == 0) {
|
if (give_item(itm->number, itm->type, u, u2, ord) == 0) {
|
||||||
given = true;
|
given = true;
|
||||||
if (*itmp != itm)
|
|
||||||
continue;
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -480,7 +480,7 @@ void pick_random_spells(faction * f, int level, spellbook * book, int num_spells
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (spellno < maxspell) {
|
if (sbe && spellno < maxspell) {
|
||||||
if (!f->spellbook) {
|
if (!f->spellbook) {
|
||||||
f->spellbook = create_spellbook(0);
|
f->spellbook = create_spellbook(0);
|
||||||
}
|
}
|
||||||
|
|
16
src/names.c
16
src/names.c
|
@ -238,9 +238,6 @@ static const char *dragon_name(const unit * u)
|
||||||
if (num_postfix == 0)
|
if (num_postfix == 0)
|
||||||
num_postfix = -1;
|
num_postfix = -1;
|
||||||
}
|
}
|
||||||
if (num_postfix <= 0) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (u) {
|
if (u) {
|
||||||
region *r = u->region;
|
region *r = u->region;
|
||||||
|
@ -264,9 +261,16 @@ static const char *dragon_name(const unit * u)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
rnd = num_postfix / 6;
|
if (num_postfix <=0) {
|
||||||
rnd = (rng_int() % rnd) + ter * rnd;
|
return NULL;
|
||||||
|
}
|
||||||
|
else if (num_postfix < 6) {
|
||||||
|
rnd = rng_int() % num_postfix;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
rnd = num_postfix / 6;
|
||||||
|
rnd = (rng_int() % rnd) + ter * rnd;
|
||||||
|
}
|
||||||
sprintf(zText, "dragon_postfix_%d", rnd);
|
sprintf(zText, "dragon_postfix_%d", rnd);
|
||||||
|
|
||||||
str = locale_getstring(default_locale, zText);
|
str = locale_getstring(default_locale, zText);
|
||||||
|
|
|
@ -15,6 +15,7 @@ without prior permission by the authors of Eressea.
|
||||||
#include "unicode.h"
|
#include "unicode.h"
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
#include <errno.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
@ -76,27 +77,24 @@ cp_convert(const char *format, char *buffer, size_t length, int codepage)
|
||||||
|
|
||||||
void log_rotate(const char *filename, int maxindex)
|
void log_rotate(const char *filename, int maxindex)
|
||||||
{
|
{
|
||||||
int n;
|
|
||||||
if (_access(filename, 4) == 0) {
|
if (_access(filename, 4) == 0) {
|
||||||
char buffer[2][MAX_PATH];
|
char buffer[2][MAX_PATH];
|
||||||
int src = 1;
|
int dst = 1;
|
||||||
assert(strlen(filename) < sizeof(buffer[0]) - 4);
|
assert(strlen(filename) < sizeof(buffer[0]) - 4);
|
||||||
for (n = 0; n < maxindex; ++n) {
|
|
||||||
sprintf(buffer[0], "%s.%d", filename, n);
|
sprintf(buffer[dst], "%s.%d", filename, maxindex);
|
||||||
if (_access(filename, 0) != 0) {
|
while (maxindex > 0) {
|
||||||
break;
|
int err, src = 1 - dst;
|
||||||
|
sprintf(buffer[src], "%s.%d", filename, --maxindex);
|
||||||
|
err = rename(buffer[src], buffer[dst]);
|
||||||
|
if (err != 0) {
|
||||||
|
log_error("log rotate %s: %s", buffer[dst], strerror(errno));
|
||||||
}
|
}
|
||||||
|
dst = src;
|
||||||
}
|
}
|
||||||
if (_access(buffer[0], 0) == 0) {
|
if (rename(filename, buffer[dst]) != 0) {
|
||||||
unlink(buffer[0]);
|
log_error("log rotate %s: %s", buffer[dst], strerror(errno));
|
||||||
}
|
}
|
||||||
while (n--) {
|
|
||||||
int dst = 1 - src;
|
|
||||||
sprintf(buffer[src], "%s.%d", filename, n);
|
|
||||||
rename(buffer[src], buffer[dst]);
|
|
||||||
src = dst;
|
|
||||||
}
|
|
||||||
rename(filename, buffer[1 - src]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue