CID 146892: null-pointer check should be an assert.

This commit is contained in:
Enno Rehling 2016-09-11 19:09:23 +02:00
parent 95481211e5
commit f07c79e5cf
2 changed files with 19 additions and 24 deletions

View file

@ -194,7 +194,6 @@ static void test_set_origin_bug(CuTest *tc) {
static void test_deadhash(CuTest *tc) { static void test_deadhash(CuTest *tc) {
faction *f; faction *f;
int no; int no;
test_setup(); test_setup();
f = test_create_faction(0); f = test_create_faction(0);
no = f->no; no = f->no;

View file

@ -232,11 +232,11 @@ static void dragon_name(unit * u)
{ {
char name[NAMESIZE + 1]; char name[NAMESIZE + 1];
int rnd, ter = 0; int rnd, ter = 0;
int anzahl = 1;
static int num_postfix; static int num_postfix;
char zText[32]; char zText[32];
const char *str; const char *str;
assert(u);
if (num_postfix == 0) { if (num_postfix == 0) {
for (num_postfix = 0;; ++num_postfix) { for (num_postfix = 0;; ++num_postfix) {
sprintf(zText, "dragon_postfix_%d", num_postfix); sprintf(zText, "dragon_postfix_%d", num_postfix);
@ -248,26 +248,22 @@ static void dragon_name(unit * u)
num_postfix = -1; num_postfix = -1;
} }
if (u) { switch (rterrain(u->region)) {
region *r = u->region; case T_PLAIN:
anzahl = u->number; ter = 1;
switch (rterrain(r)) { break;
case T_PLAIN: case T_MOUNTAIN:
ter = 1; ter = 2;
break; break;
case T_MOUNTAIN: case T_DESERT:
ter = 2; ter = 3;
break; break;
case T_DESERT: case T_SWAMP:
ter = 3; ter = 4;
break; break;
case T_SWAMP: case T_GLACIER:
ter = 4; ter = 5;
break; break;
case T_GLACIER:
ter = 5;
break;
}
} }
if (num_postfix <=0) { if (num_postfix <=0) {
@ -285,7 +281,7 @@ static void dragon_name(unit * u)
str = locale_getstring(default_locale, zText); str = locale_getstring(default_locale, zText);
assert(str != NULL); assert(str != NULL);
if (anzahl > 1) { if (u->number > 1) {
const char *no_article = strchr((const char *)str, ' '); const char *no_article = strchr((const char *)str, ' ');
assert(no_article); assert(no_article);
// TODO: localization // TODO: localization
@ -308,7 +304,7 @@ static void dragon_name(unit * u)
sz += strlcat(name, " ", sizeof(name)); sz += strlcat(name, " ", sizeof(name));
sz += strlcat(name, n, sizeof(name)); sz += strlcat(name, n, sizeof(name));
} }
if (u && (rng_int() % 3 == 0)) { if (rng_int() % 3 == 0) {
sz += strlcat(name, " von ", sizeof(name)); sz += strlcat(name, " von ", sizeof(name));
sz += strlcat(name, (const char *)rname(u->region, default_locale), sizeof(name)); sz += strlcat(name, (const char *)rname(u->region, default_locale), sizeof(name));
} }