Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix FFL_NOTIMEOUT related crash in E2 #43

Merged
merged 8 commits into from
Oct 18, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
942 changes: 465 additions & 477 deletions src/kernel/curse.c

Large diffs are not rendered by default.

12 changes: 2 additions & 10 deletions src/kernel/curse.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (c) 1998-2010, Enno Rehling <[email protected]>
Copyright (c) 1998-2014, Enno Rehling <[email protected]>
Katja Zedel <[email protected]
Christian Schlittchen <[email protected]>

Expand Down Expand Up @@ -251,7 +251,7 @@ extern "C" {
bool is_cursed_internal(struct attrib *ap, const curse_type * ctype);
/* ignoriert CURSE_ISNEW */

extern void remove_curse(struct attrib **ap, const struct curse *c);
bool remove_curse(struct attrib **ap, const struct curse *c);
/* l�scht einen konkreten Spruch auf einem Objekt.
*/

Expand Down Expand Up @@ -280,11 +280,6 @@ extern "C" {
* unterschiedlich gew�nscht sein
* */

extern struct curse *get_cursex(struct attrib *ap, const curse_type * ctype,
variant data, bool(*compare) (const struct curse *, variant));
/* gibt pointer auf die erste curse-struct zur�ck, deren Typ ctype ist,
* und f�r die compare() true liefert, oder einen NULL-pointer.
* */
extern struct curse *get_curse(struct attrib *ap, const curse_type * ctype);
/* gibt pointer auf die erste curse-struct zur�ck, deren Typ ctype ist,
* oder einen NULL-pointer
Expand All @@ -303,9 +298,6 @@ extern "C" {
extern void curse_done(struct attrib *a);
extern int curse_age(struct attrib *a);

extern bool cmp_curse(const struct attrib *a, const void *data);
extern bool cmp_cursetype(const struct attrib *a, const void *data);

extern float destr_curse(struct curse *c, int cast_level, float force);

extern int resolve_curse(variant data, void *address);
Expand Down
17 changes: 17 additions & 0 deletions src/kernel/faction.test.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <platform.h>

#include <kernel/ally.h>
#include <kernel/faction.h>
#include <kernel/types.h>
#include <kernel/race.h>
Expand All @@ -13,6 +14,21 @@
#include <assert.h>
#include <stdio.h>

static void test_remove_empty_factions_allies(CuTest *tc) {
faction *f1, *f2;
region *r;

test_cleanup();
r = test_create_region(0, 0, 0);
f1 = test_create_faction(0);
test_create_unit(f1, r);
f2 = test_create_faction(0);
ally_add(&f1->allies, f2);
remove_empty_factions();
CuAssertPtrEquals(tc, 0, f1->allies);
test_cleanup();
}

static void test_remove_empty_factions(CuTest *tc) {
faction *f, *fm;
int fno;
Expand Down Expand Up @@ -95,6 +111,7 @@ CuSuite *get_faction_suite(void)
CuSuite *suite = CuSuiteNew();
SUITE_ADD_TEST(suite, test_addfaction);
SUITE_ADD_TEST(suite, test_remove_empty_factions);
SUITE_ADD_TEST(suite, test_remove_empty_factions_allies);
SUITE_ADD_TEST(suite, test_remove_dead_factions);
SUITE_ADD_TEST(suite, test_get_monsters);
return suite;
Expand Down
3 changes: 0 additions & 3 deletions src/kernel/save.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,6 @@ char *rns(FILE * f, char *c, size_t size)
return c;
}

extern unsigned int __at_hashkey(const char *s);


static unit *unitorders(FILE * F, int enc, struct faction *f)
{
Expand Down Expand Up @@ -1315,7 +1313,6 @@ faction *readfaction(struct gamedata * data)
f->flags = FFL_NPC | FFL_NOIDLEOUT;
}
}
assert((f->flags&FFL_SAVEMASK) == f->flags);

a_read(data->store, &f->attribs, f);
if (data->version >= CLAIM_VERSION) {
Expand Down
32 changes: 4 additions & 28 deletions src/modules/gmcmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,6 @@

/* util includes */
#include <util/attrib.h>
#include <util/base36.h>
#include <util/event.h>
#include <util/goodies.h>
#include <util/language.h>
#include <util/lists.h>
#include <util/log.h>
#include <util/umlaut.h>
#include <util/parser.h>
#include <util/rng.h>

#include <storage.h>

/* libc includes */
Expand All @@ -56,34 +46,20 @@
static int read_permissions(attrib * a, void *owner, struct storage *store)
{
attrib *attr = NULL;
a_read(store, &attr, NULL);
a_free(attr);
a_read(store, &attr, owner);
a_remove(&attr, a);
return AT_READ_OK;
}

struct attrib_type at_permissions = {
"GM:permissions",
NULL, NULL, NULL,
NULL, read_permissions,
ATF_UNIQUE
};

static int read_gmcreate(attrib * a, void *owner, struct storage *store)
{
char zText[32];
READ_TOK(store, zText, sizeof(zText));
return AT_READ_OK;
}

/* at_gmcreate specifies that the owner can create items of a particular type */
attrib_type at_gmcreate = {
"GM:create",
NULL, NULL, NULL,
NULL, read_gmcreate
};

void register_gmcmd(void)
{
at_register(&at_gmcreate);
at_register(&at_permissions);
at_deprecate("GM:create", read_gmcreate);
at_deprecate("GM:permissions", read_permissions);
}
1 change: 1 addition & 0 deletions src/test_eressea.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ int RunAllTests(void)
ADD_TESTS(suite, race);
/* util */
ADD_TESTS(suite, config);
ADD_TESTS(suite, attrib);
ADD_TESTS(suite, base36);
ADD_TESTS(suite, bsdstring);
ADD_TESTS(suite, functions);
Expand Down
41 changes: 27 additions & 14 deletions src/tests.h
Original file line number Diff line number Diff line change
@@ -1,25 +1,38 @@
#ifndef ERESSEA_TESTS_H
#define ERESSEA_TESTS_H

#include <stdlib.h>

#ifdef __cplusplus
extern "C" {
#endif

void test_cleanup(void);
struct region;
struct unit;
struct faction;
struct building;
struct ship;
struct item_type;
struct building_type;
struct ship_type;
struct terrain_type;

void test_cleanup(void);

struct terrain_type * test_create_terrain(const char * name, unsigned int flags);
struct race *test_create_race(const char *name);
struct region *test_create_region(int x, int y,
const struct terrain_type *terrain);
struct faction *test_create_faction(const struct race *rc);
struct unit *test_create_unit(struct faction *f, struct region *r);
void test_create_world(void);
struct building * test_create_building(struct region * r, const struct building_type * btype);
struct ship * test_create_ship(struct region * r, const struct ship_type * stype);
struct item_type * test_create_itemtype(const char * name);
struct ship_type *test_create_shiptype(const char * name);
struct building_type *test_create_buildingtype(const char *name);
struct terrain_type * test_create_terrain(const char * name, unsigned int flags);
struct race *test_create_race(const char *name);
struct region *test_create_region(int x, int y,
const struct terrain_type *terrain);
struct faction *test_create_faction(const struct race *rc);
struct unit *test_create_unit(struct faction *f, struct region *r);
void test_create_world(void);
struct building * test_create_building(struct region * r, const struct building_type * btype);
struct ship * test_create_ship(struct region * r, const struct ship_type * stype);
struct item_type * test_create_itemtype(const char * name);
struct ship_type *test_create_shiptype(const char * name);
struct building_type *test_create_buildingtype(const char *name);

int RunAllTests(void);
int RunAllTests(void);

#ifdef __cplusplus
}
Expand Down
74 changes: 36 additions & 38 deletions src/triggers/removecurse.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
Copyright (c) 1998-2010, Enno Rehling <[email protected]>
Katja Zedel <[email protected]
Christian Schlittchen <[email protected]>
Copyright (c) 1998-2014, Enno Rehling <[email protected]>
Katja Zedel <[email protected]
Christian Schlittchen <[email protected]>

Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
Expand Down Expand Up @@ -41,68 +41,66 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <stdio.h>

typedef struct removecurse_data {
curse *curse;
unit *target;
curse *curse;
unit *target;
} removecurse_data;

static void removecurse_init(trigger * t)
{
t->data.v = calloc(sizeof(removecurse_data), 1);
t->data.v = calloc(sizeof(removecurse_data), 1);
}

static void removecurse_free(trigger * t)
{
free(t->data.v);
free(t->data.v);
}

static int removecurse_handle(trigger * t, void *data)
{
/* call an event handler on removecurse.
* data.v -> ( variant event, int timer )
*/
removecurse_data *td = (removecurse_data *) t->data.v;
if (td->curse && td->target) {
attrib *a = a_select(td->target->attribs, td->curse, cmp_curse);
if (a) {
a_remove(&td->target->attribs, a);
} else
log_error("could not perform removecurse::handle()\n");
}
unused_arg(data);
return 0;
/* call an event handler on removecurse.
* data.v -> ( variant event, int timer )
*/
removecurse_data *td = (removecurse_data *)t->data.v;
if (td->curse && td->target) {
if (!remove_curse(&td->target->attribs, td->curse)) {
log_error("could not perform removecurse::handle()\n");
}
}
unused_arg(data);
return 0;
}

static void removecurse_write(const trigger * t, struct storage *store)
{
removecurse_data *td = (removecurse_data *) t->data.v;
WRITE_TOK(store, td->target ? itoa36(td->target->no) : 0);
WRITE_INT(store, td->curse ? td->curse->no : 0);
removecurse_data *td = (removecurse_data *)t->data.v;
WRITE_TOK(store, td->target ? itoa36(td->target->no) : 0);
WRITE_INT(store, td->curse ? td->curse->no : 0);
}

static int removecurse_read(trigger * t, struct storage *store)
{
removecurse_data *td = (removecurse_data *) t->data.v;
removecurse_data *td = (removecurse_data *)t->data.v;

read_reference(&td->target, store, read_unit_reference, resolve_unit);
read_reference(&td->curse, store, read_int, resolve_curse);
read_reference(&td->target, store, read_unit_reference, resolve_unit);
read_reference(&td->curse, store, read_int, resolve_curse);

return AT_READ_OK;
return AT_READ_OK;
}

trigger_type tt_removecurse = {
"removecurse",
removecurse_init,
removecurse_free,
removecurse_handle,
removecurse_write,
removecurse_read
"removecurse",
removecurse_init,
removecurse_free,
removecurse_handle,
removecurse_write,
removecurse_read
};

trigger *trigger_removecurse(curse * c, unit * target)
{
trigger *t = t_new(&tt_removecurse);
removecurse_data *td = (removecurse_data *) t->data.v;
td->curse = c;
td->target = target;
return t;
trigger *t = t_new(&tt_removecurse);
removecurse_data *td = (removecurse_data *)t->data.v;
td->curse = c;
td->target = target;
return t;
}
1 change: 1 addition & 0 deletions src/util/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ project(util C)

SET(_TEST_FILES
base36.test.c
attrib.test.c
strings.test.c
bsdstring.test.c
functions.test.c
Expand Down
Loading