null-pointer crash when running with --lomem

This commit is contained in:
Enno Rehling 2005-09-03 06:49:26 +00:00
parent 0e74ca4ef7
commit d09071eff7
1 changed files with 152 additions and 152 deletions

View File

@ -39,36 +39,36 @@
const unit *
random_unit_in_faction(const faction *f)
{
unit *u;
int c = 0, u_nr;
unit *u;
int c = 0, u_nr;
for(u = f->units; u; u=u->next) c++;
for(u = f->units; u; u=u->next) c++;
u_nr = rand()%c;
c = 0;
u_nr = rand()%c;
c = 0;
for(u = f->units; u; u=u->next)
if(u_nr == c) return u;
for(u = f->units; u; u=u->next)
if(u_nr == c) return u;
/* Hier sollte er nie ankommen */
return NULL;
/* Hier sollte er nie ankommen */
return NULL;
}
const char *
factionname(const faction * f)
{
typedef char name[OBJECTIDSIZE + 1];
static name idbuf[8];
static int nextbuf = 0;
typedef char name[OBJECTIDSIZE + 1];
static name idbuf[8];
static int nextbuf = 0;
char *buf = idbuf[(++nextbuf) % 8];
char *buf = idbuf[(++nextbuf) % 8];
if (f && f->name) {
sprintf(buf, "%s (%s)", strcheck(f->name, NAMESIZE), itoa36(f->no));
} else {
sprintf(buf, "Unbekannte Partei (?)");
}
return buf;
if (f && f->name) {
sprintf(buf, "%s (%s)", strcheck(f->name, NAMESIZE), itoa36(f->no));
} else {
sprintf(buf, "Unbekannte Partei (?)");
}
return buf;
}
void *
@ -81,13 +81,13 @@ resolve_faction(variant id) {
static int
unused_faction_id(void)
{
int id = rand()%MAX_FACTION_ID;
int id = rand()%MAX_FACTION_ID;
while(!faction_id_is_unused(id)) {
id++; if(id == MAX_FACTION_ID) id = 0;
}
while(!faction_id_is_unused(id)) {
id++; if(id == MAX_FACTION_ID) id = 0;
}
return id;
return id;
}
faction *
@ -168,153 +168,153 @@ checkpasswd(const faction * f, const char * passwd, boolean shortp)
slist = slist->next;
}
#endif
if (strcasecmp(f->passw, passwd)==0) return true;
if (strcasecmp(f->override, passwd)==0) return true;
return false;
if (strcasecmp(f->passw, passwd)==0) return true;
if (strcasecmp(f->override, passwd)==0) return true;
return false;
}
void
destroyfaction(faction * f)
{
region *rc;
unit *u;
faction *ff;
region *rc;
unit *u;
faction *ff;
if (!f->alive) return;
if (!f->alive) return;
while (f->battles) {
struct bmsg * bm = f->battles;
f->battles = bm->next;
free_messagelist(bm->msgs);
if (bm->msgs) free_messagelist(bm->msgs);
free(bm);
}
for (u=f->units;u;u=u->nextF) {
region * r = u->region;
unit * au;
int number = 0;
struct friend {
struct friend * next;
int number;
faction * faction;
unit * unit;
} * friends = NULL;
for (au=r->units;au;au=au->next) if (au->faction!=f) {
if (alliedunit(u, au->faction, HELP_ALL)) {
struct friend * nf, ** fr = &friends;
for (u=f->units;u;u=u->nextF) {
region * r = u->region;
unit * au;
int number = 0;
struct friend {
struct friend * next;
int number;
faction * faction;
unit * unit;
} * friends = NULL;
for (au=r->units;au;au=au->next) if (au->faction!=f) {
if (alliedunit(u, au->faction, HELP_ALL)) {
struct friend * nf, ** fr = &friends;
while (*fr && (*fr)->faction->no<au->faction->no) fr = &(*fr)->next;
nf = *fr;
if (nf==NULL || nf->faction!=au->faction) {
nf = calloc(sizeof(struct friend), 1);
nf->next = *fr;
nf->faction = au->faction;
nf->unit = au;
*fr = nf;
}
nf->number += au->number;
number += au->number;
}
}
if (friends && number) {
struct friend * nf = friends;
while (nf) {
unit * u2 = nf->unit;
while (*fr && (*fr)->faction->no<au->faction->no) fr = &(*fr)->next;
nf = *fr;
if (nf==NULL || nf->faction!=au->faction) {
nf = calloc(sizeof(struct friend), 1);
nf->next = *fr;
nf->faction = au->faction;
nf->unit = au;
*fr = nf;
}
nf->number += au->number;
number += au->number;
}
}
if (friends && number) {
struct friend * nf = friends;
while (nf) {
unit * u2 = nf->unit;
#ifdef NEW_ITEMS
item * itm = u->items;
while(itm){
const item_type * itype = itm->type;
item * itn = itm->next;
int n = itm->number;
n = n * nf->number / number;
if (n>0) {
i_change(&u->items, itype, -n);
i_change(&u2->items, itype, n);
}
itm = itn;
}
item * itm = u->items;
while(itm){
const item_type * itype = itm->type;
item * itn = itm->next;
int n = itm->number;
n = n * nf->number / number;
if (n>0) {
i_change(&u->items, itype, -n);
i_change(&u2->items, itype, n);
}
itm = itn;
}
#else
resource_t res;
for (res = 0; res <= R_SILVER; ++res) {
int n = get_resource(u, res);
if (n<=0) continue;
n = n * nf->number / number;
if (n<=0) continue;
change_resource(u, res, -n);
change_resource(u2, res, n);
}
resource_t res;
for (res = 0; res <= R_SILVER; ++res) {
int n = get_resource(u, res);
if (n<=0) continue;
n = n * nf->number / number;
if (n<=0) continue;
change_resource(u, res, -n);
change_resource(u2, res, n);
}
#endif
number -= nf->number;
nf = nf->next;
free(friends);
friends = nf;
}
friends = NULL;
}
if (rterrain(r) != T_OCEAN && !!playerrace(u->race)) {
const race * rc = u->race;
int p = rpeasants(u->region);
int m = rmoney(u->region);
int h = rhorses(u->region);
number -= nf->number;
nf = nf->next;
free(friends);
friends = nf;
}
friends = NULL;
}
if (rterrain(r) != T_OCEAN && !!playerrace(u->race)) {
const race * rc = u->race;
int p = rpeasants(u->region);
int m = rmoney(u->region);
int h = rhorses(u->region);
/* Personen gehen nur an die Bauern, wenn sie auch von dort
* stammen */
if ((rc->ec_flags & ECF_REC_UNLIMITED)==0) {
if (rc->ec_flags & ECF_REC_HORSES) { /* Zentauren an die Pferde */
h += u->number;
} else if (rc == new_race[RC_URUK]){ /* Orks zählen nur zur Hälfte */
p += u->number/2;
} else {
p += u->number;
}
}
m += get_money(u);
h += get_item(u, I_HORSE);
rsetpeasants(r, p);
rsethorses(r, h);
rsetmoney(r, m);
/* Personen gehen nur an die Bauern, wenn sie auch von dort
* stammen */
if ((rc->ec_flags & ECF_REC_UNLIMITED)==0) {
if (rc->ec_flags & ECF_REC_HORSES) { /* Zentauren an die Pferde */
h += u->number;
} else if (rc == new_race[RC_URUK]){ /* Orks zählen nur zur Hälfte */
p += u->number/2;
} else {
p += u->number;
}
}
m += get_money(u);
h += get_item(u, I_HORSE);
rsetpeasants(r, p);
rsethorses(r, h);
rsetmoney(r, m);
}
set_number(u, 0);
}
f->alive = 0;
/* no way! f->units = NULL; */
handle_event(&f->attribs, "destroy", f);
for (ff = factions; ff; ff = ff->next) {
group *g;
ally *sf, *sfn;
}
set_number(u, 0);
}
f->alive = 0;
/* no way! f->units = NULL; */
handle_event(&f->attribs, "destroy", f);
for (ff = factions; ff; ff = ff->next) {
group *g;
ally *sf, *sfn;
/* Alle HELFE für die Partei löschen */
for (sf = ff->allies; sf; sf = sf->next) {
if (sf->faction == f) {
removelist(&ff->allies, sf);
break;
}
}
for(g=ff->groups; g; g=g->next) {
for (sf = g->allies; sf;) {
sfn = sf->next;
if (sf->faction == f) {
removelist(&g->allies, sf);
break;
}
sf = sfn;
}
}
}
/* Alle HELFE für die Partei löschen */
for (sf = ff->allies; sf; sf = sf->next) {
if (sf->faction == f) {
removelist(&ff->allies, sf);
break;
}
}
for(g=ff->groups; g; g=g->next) {
for (sf = g->allies; sf;) {
sfn = sf->next;
if (sf->faction == f) {
removelist(&g->allies, sf);
break;
}
sf = sfn;
}
}
}
/* units of other factions that were disguised as this faction
* have their disguise replaced by ordinary faction hiding. */
for (rc=regions; rc; rc=rc->next) {
for(u=rc->units; u; u=u->next) {
attrib *a = a_find(u->attribs, &at_otherfaction);
if(!a) continue;
if (get_otherfaction(a) == f) {
a_removeall(&u->attribs, &at_otherfaction);
fset(u, UFL_PARTEITARNUNG);
}
}
}
/* units of other factions that were disguised as this faction
* have their disguise replaced by ordinary faction hiding. */
for (rc=regions; rc; rc=rc->next) {
for(u=rc->units; u; u=u->next) {
attrib *a = a_find(u->attribs, &at_otherfaction);
if(!a) continue;
if (get_otherfaction(a) == f) {
a_removeall(&u->attribs, &at_otherfaction);
fset(u, UFL_PARTEITARNUNG);
}
}
}
}
int