stop reallocation spell parameters.

fix involuntary tree growth in test, message check.
This commit is contained in:
Enno Rehling 2018-05-06 15:49:34 +02:00
parent cd2435dbb0
commit cd2624de8a
9 changed files with 64 additions and 44 deletions

View File

@ -1,6 +1,6 @@
require 'tests.e2.spells'
require 'tests.e2.e2features'
require 'tests.e2.insects'
require 'tests.e2.spells'
require 'tests.e2.buildings'
require 'tests.e2.production'
require 'tests.e2.adamantium'

View File

@ -9,6 +9,7 @@ function setup()
eressea.settings.set("rules.ship.storms", "0")
eressea.settings.set("rules.encounters", "0")
eressea.settings.set("magic.regeneration.enable", "0")
eressea.settings.set("rules.grow.formula", "0")
eressea.settings.set("study.random_progress", "0")
end

View File

@ -12,6 +12,39 @@ function setup()
eressea.settings.set("magic.fumble.enable", "0")
end
function disable_pull_astral()
local r = region.create(0, 0, "plain")
local f = faction.create("human")
local u1 = unit.create(f, r, 1)
local u2 = unit.create(f, r, 1)
u1.magic = "gray"
u1:set_skill("magic", 6)
u1.aura = 1
u1:add_spell("pull_astral")
u1:clear_orders()
u1:add_order("ZAUBERE Astraler~Ruf " .. itoa36(u2.id))
-- process_orders()
-- assert_equal(1, f:count_msg_type('error194'), 'no target region')
-- assert_equal(1, f:count_msg_type('error209'), 'bad arguments')
u1:clear_orders()
u1:add_order("ZAUBERE Astraler~Ruf 1 0 " .. itoa36(u2.id))
process_orders()
assert_equal(1, f:count_msg_type('error194'), 'no target region')
assert_equal(0, f:count_msg_type('error209'), 'bad arguments')
assert_equal(1, f:count_msg_type('spellregionresists'), 'no such region')
u1:add_order("ZAUBERE Astraler~Ruf 0 0 " .. itoa36(u2.id))
process_orders()
assert_equal(0, f:count_msg_type('error194'), 'no target region')
assert_equal(0, f:count_msg_type('error209'), 'bad arguments')
assert_equal(0, f:count_msg_type('spellregionresists'), 'no such region')
for k, v in ipairs(f.messages) do
print(v)
end
assert_equal(u1, u2)
end
function test_shapeshift()
local r = region.create(42, 0, "plain")
local f = faction.create("demon", "noreply@eressea.de", "de")

View File

@ -21,7 +21,7 @@ function test_create_bogus()
u:clear_orders()
u:add_order("ZAUBERE 'Erschaffe Katastrophe'")
process_orders()
assert_equal(f.messages[3], 'error173') -- HACKity HACK
assert_equal(1, f:count_msg_type('error173'), 'spell not found')
end
function test_create_roi()

View File

@ -39,6 +39,7 @@ without prior permission by the authors of Eressea.
#include <tolua.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
typedef struct helpmode {

View File

@ -476,22 +476,17 @@ static int tolua_write_reports(lua_State * L)
return 1;
}
static int tolua_process_orders(lua_State * L)
{
UNUSED_ARG(L);
#if 0
order * ord = parse_order("@GIB xmis ALLES Gurgelkraut", default_locale);
assert(ord);
free_order(ord);
return 0;
#endif
processorders();
return 0;
}
static int tolua_turn_begin(lua_State * L)
{
faction *f;
UNUSED_ARG(L);
for (f = factions; f; f = f->next) {
if (f->msgs) {
free_messagelist(f->msgs->begin);
free(f->msgs);
f->msgs = NULL;
}
}
turn_begin();
return 0;
}
@ -510,6 +505,14 @@ static int tolua_turn_end(lua_State * L)
return 0;
}
static int tolua_process_orders(lua_State * L)
{
UNUSED_ARG(L);
tolua_turn_begin(L);
tolua_turn_process(L);
return tolua_turn_end(L);
}
static int tolua_write_passwords(lua_State * L)
{
int result = writepasswd();

View File

@ -4140,13 +4140,6 @@ void turn_end(void)
update_spells();
}
void processorders(void)
{
turn_begin();
turn_process();
turn_end();
}
void update_subscriptions(void)
{
FILE *F;

View File

@ -53,7 +53,6 @@ extern "C" {
int enter_building(struct unit *u, struct order *ord, int id, bool report);
int enter_ship(struct unit *u, struct order *ord, int id, bool report);
void processorders(void);
void turn_begin(void);
void turn_process(void);
void turn_end(void);

View File

@ -1822,7 +1822,7 @@ addparam_region(const char *const param[], spllprm ** spobjp, const unit * u,
order * ord)
{
assert(param[0]);
if (param[1] == 0) {
if (param[1] == NULL) {
/* Fehler: Zielregion vergessen */
cmistake(u, ord, 194, MSG_MAGIC);
return -1;
@ -2014,13 +2014,13 @@ static spellparameter *add_spellparameter(region * target_r, unit * u,
/* im Endeffekt waren es evtl. nur p parameter (wegen TEMP) */
par->length = p;
if (fail || par->length < minlen) {
if (par->length < minlen) {
cmistake(u, ord, 209, MSG_MAGIC);
free_spellparameter(par);
return NULL;
}
return par;
return fail ? NULL : par;
}
struct unit * co_get_caster(const struct castorder * co) {
@ -2412,6 +2412,7 @@ static bool is_moving_ship(ship * sh)
return false;
}
#define MAX_PARAMETERS 8
static castorder *cast_cmd(unit * u, order * ord)
{
char token[128];
@ -2612,33 +2613,22 @@ static castorder *cast_cmd(unit * u, order * ord)
}
/* Weitere Argumente zusammenbasteln */
if (sp->parameter) {
char **params = (char**)malloc(2 * sizeof(char *));
int p = 0, size = 2;
char *params[MAX_PARAMETERS];
int i, p = 0;
for (;;) {
s = gettoken(token, sizeof(token));
if (!s || *s == 0)
if (!s || *s == 0) {
break;
if (p + 1 >= size) {
char ** tmp;
tmp = (char**)realloc(params, sizeof(char *) * size * 2);
if (tmp) {
size *= 2;
params = tmp;
}
else {
log_error("error allocationg %d bytes: %s", size * 2, strerror(errno));
break;
}
}
assert(p + 1 < MAX_PARAMETERS);
params[p++] = str_strdup(s);
}
params[p] = 0;
args =
add_spellparameter(target_r, caster, sp->parameter,
(const char *const *)params, p, ord);
for (p = 0; params[p]; ++p)
free(params[p]);
free(params);
for (i = 0; i != p; ++i) {
free(params[i]);
}
if (args == NULL) {
/* Syntax war falsch */
return 0;