forked from github/server
fix allies with null faction (to be resolved later).
This commit is contained in:
parent
f27a77d288
commit
cf110d7788
2 changed files with 52 additions and 36 deletions
|
@ -4,19 +4,21 @@
|
|||
#include <stdlib.h>
|
||||
|
||||
ally * ally_find(ally *al, const struct faction *f) {
|
||||
for (;al;al=al->next) {
|
||||
if (al->faction==f) return al;
|
||||
for (; al; al = al->next) {
|
||||
if (al->faction == f) return al;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
ally * ally_add(ally **al_p, struct faction *f) {
|
||||
ally * al;
|
||||
if (f) {
|
||||
while (*al_p) {
|
||||
al = *al_p;
|
||||
if (al->faction==f) return al;
|
||||
if (al->faction == f) return al;
|
||||
al_p = &al->next;
|
||||
}
|
||||
}
|
||||
al = (ally *)malloc(sizeof(ally));
|
||||
al->faction = f;
|
||||
al->status = 0;
|
||||
|
@ -29,7 +31,7 @@ void ally_remove(ally **al_p, struct faction *f) {
|
|||
ally * al;
|
||||
while (*al_p) {
|
||||
al = *al_p;
|
||||
if (al->faction==f) {
|
||||
if (al->faction == f) {
|
||||
*al_p = al->next;
|
||||
free(al);
|
||||
break;
|
||||
|
|
|
@ -19,6 +19,20 @@ static void test_ally(CuTest * tc)
|
|||
CuAssertPtrEquals(tc, 0, ally_find(al, f1));
|
||||
}
|
||||
|
||||
static void test_ally_null(CuTest * tc)
|
||||
{
|
||||
ally *a1 = 0, *a2 = 0;
|
||||
|
||||
a1 = ally_add(&a1, 0);
|
||||
a2 = ally_add(&a1, 0);
|
||||
CuAssertPtrNotNull(tc, a1);
|
||||
CuAssertPtrNotNull(tc, a2);
|
||||
CuAssertPtrEquals(tc, a2, a1->next);
|
||||
CuAssertPtrEquals(tc, 0, a2->next);
|
||||
free(a1);
|
||||
free(a2);
|
||||
}
|
||||
|
||||
CuSuite *get_ally_suite(void)
|
||||
{
|
||||
CuSuite *suite = CuSuiteNew();
|
||||
|
|
Loading…
Reference in a new issue