forked from github/server
Merge pull request #507 from ennorehling/hotfix/bug-2201-remove_empty_factions
Hotfix bug 2201, crash E3 turn 351
This commit is contained in:
commit
13156a47a4
|
@ -1,3 +1,3 @@
|
||||||
#define VERSION_MAJOR 3
|
#define VERSION_MAJOR 3
|
||||||
#define VERSION_MINOR 8
|
#define VERSION_MINOR 8
|
||||||
#define VERSION_BUILD 7
|
#define VERSION_BUILD 8
|
||||||
|
|
|
@ -74,9 +74,6 @@ faction *factions;
|
||||||
static void free_faction(faction * f)
|
static void free_faction(faction * f)
|
||||||
{
|
{
|
||||||
funhash(f);
|
funhash(f);
|
||||||
if (f->alliance && f->alliance->_leader == f) {
|
|
||||||
setalliance(f, 0);
|
|
||||||
}
|
|
||||||
if (f->msgs) {
|
if (f->msgs) {
|
||||||
free_messagelist(f->msgs->begin);
|
free_messagelist(f->msgs->begin);
|
||||||
free(f->msgs);
|
free(f->msgs);
|
||||||
|
@ -454,7 +451,7 @@ void destroyfaction(faction ** fp)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (f->alliance && f->alliance->_leader == f) {
|
if (f->alliance) {
|
||||||
setalliance(f, 0);
|
setalliance(f, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -681,8 +678,6 @@ void remove_empty_factions(void)
|
||||||
if (!(f->_alive && f->units!=NULL) && !fval(f, FFL_NOIDLEOUT)) {
|
if (!(f->_alive && f->units!=NULL) && !fval(f, FFL_NOIDLEOUT)) {
|
||||||
log_debug("dead: %s", factionname(f));
|
log_debug("dead: %s", factionname(f));
|
||||||
destroyfaction(fp);
|
destroyfaction(fp);
|
||||||
free_faction(f);
|
|
||||||
free(f);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
fp = &(*fp)->next;
|
fp = &(*fp)->next;
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
#include "monster.h"
|
#include "monster.h"
|
||||||
#include <CuTest.h>
|
#include <CuTest.h>
|
||||||
#include <tests.h>
|
#include <tests.h>
|
||||||
|
#include <quicklist.h>
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
@ -46,8 +47,10 @@ static void test_remove_empty_factions_alliance(CuTest *tc) {
|
||||||
al = makealliance(0, "Hodor");
|
al = makealliance(0, "Hodor");
|
||||||
setalliance(f, al);
|
setalliance(f, al);
|
||||||
CuAssertPtrEquals(tc, f, alliance_get_leader(al));
|
CuAssertPtrEquals(tc, f, alliance_get_leader(al));
|
||||||
|
CuAssertIntEquals(tc, 1, ql_length(al->members));
|
||||||
remove_empty_factions();
|
remove_empty_factions();
|
||||||
CuAssertPtrEquals(tc, 0, al->_leader);
|
CuAssertPtrEquals(tc, 0, al->_leader);
|
||||||
|
CuAssertIntEquals(tc, 0, ql_length(al->members));
|
||||||
test_cleanup();
|
test_cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,6 +64,9 @@ static void test_remove_empty_factions(CuTest *tc) {
|
||||||
f = test_create_faction(0);
|
f = test_create_faction(0);
|
||||||
fno = f->no;
|
fno = f->no;
|
||||||
remove_empty_factions();
|
remove_empty_factions();
|
||||||
|
CuAssertIntEquals(tc, false, f->_alive);
|
||||||
|
CuAssertPtrEquals(tc, fm, factions);
|
||||||
|
CuAssertPtrEquals(tc, NULL, fm->next);
|
||||||
CuAssertPtrEquals(tc, 0, findfaction(fno));
|
CuAssertPtrEquals(tc, 0, findfaction(fno));
|
||||||
CuAssertPtrEquals(tc, fm, get_monsters());
|
CuAssertPtrEquals(tc, fm, get_monsters());
|
||||||
test_cleanup();
|
test_cleanup();
|
||||||
|
|
Loading…
Reference in New Issue