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