reduce dependence on platform.h.

gradually stop using MAX and MIN (mistakes were made).
This commit is contained in:
Enno Rehling 2017-12-28 18:29:40 +01:00
parent 3c16267246
commit 5b1d27542a
53 changed files with 288 additions and 220 deletions

View file

@ -28,7 +28,7 @@ IF (CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wsign-compare -Wall -Werror -Wno-unknown-pragmas -Wstrict-prototypes -Wpointer-arith -Wno-char-subscripts -Wno-long-long") SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wsign-compare -Wall -Werror -Wno-unknown-pragmas -Wstrict-prototypes -Wpointer-arith -Wno-char-subscripts -Wno-long-long")
# SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c89") # SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c89")
ELSEIF(MSVC) ELSEIF(MSVC)
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /Wall /WX /MP") SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W4 /WX /MP /D_CRT_SECURE_NO_WARNINGS /D_USE_MATH_DEFINES")
set(CMAKE_EXE_LINKER_FLAGS_DEBUG set(CMAKE_EXE_LINKER_FLAGS_DEBUG
"${CMAKE_EXE_LINKER_FLAGS_DEBUG} /NODEFAULTLIB:libc.lib /NODEFAULTLIB:libcmt.lib /NODEFAULTLIB:libcd.lib /NODEFAULTLIB:libcmtd.lib /NODEFAULTLIB:msvcrt.lib") "${CMAKE_EXE_LINKER_FLAGS_DEBUG} /NODEFAULTLIB:libc.lib /NODEFAULTLIB:libcmt.lib /NODEFAULTLIB:libcd.lib /NODEFAULTLIB:libcmtd.lib /NODEFAULTLIB:msvcrt.lib")
set(CMAKE_EXE_LINKER_FLAGS_RELEASE set(CMAKE_EXE_LINKER_FLAGS_RELEASE

View file

@ -34,6 +34,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <util/log.h> #include <util/log.h>
#include <util/gamedata.h> #include <util/gamedata.h>
#include <util/resolve.h> #include <util/resolve.h>
#include <util/strings.h>
#include <storage.h> #include <storage.h>
@ -69,7 +70,7 @@ static int dict_read(attrib * a, void *owner, gamedata *data)
int n; int n;
READ_STR(store, name, sizeof(name)); READ_STR(store, name, sizeof(name));
dd->name = strdup(name); dd->name = str_strdup(name);
READ_INT(store, &n); READ_INT(store, &n);
dd->type = (dict_type)n; dd->type = (dict_type)n;
if (dd->type == TINTEGER) { if (dd->type == TINTEGER) {
@ -170,7 +171,7 @@ attrib_type at_dict = {
void dict_set(attrib * a, const char * name, int value) void dict_set(attrib * a, const char * name, int value)
{ {
dict_data *dd = (dict_data *)a->data.v; dict_data *dd = (dict_data *)a->data.v;
dd->name = strdup(name); dd->name = str_strdup(name);
dd->type = TINTEGER; dd->type = TINTEGER;
dd->data.i = value; dd->data.i = value;
} }

View file

@ -21,6 +21,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include "racename.h" #include "racename.h"
#include <util/attrib.h> #include <util/attrib.h>
#include <util/strings.h>
/* libc includes */ /* libc includes */
#include <stdlib.h> #include <stdlib.h>
@ -43,7 +44,7 @@ void set_racename(attrib ** palist, const char *name)
attrib *a = a_find(*palist, &at_racename); attrib *a = a_find(*palist, &at_racename);
if (!a && name) { if (!a && name) {
a = a_add(palist, a_new(&at_racename)); a = a_add(palist, a_new(&at_racename));
a->data.v = strdup(name); a->data.v = str_strdup(name);
} }
else if (a && !name) { else if (a && !name) {
a_remove(palist, a); a_remove(palist, a);
@ -51,7 +52,7 @@ void set_racename(attrib ** palist, const char *name)
else if (a) { else if (a) {
if (strcmp(a->data.v, name) != 0) { if (strcmp(a->data.v, name) != 0) {
free(a->data.v); free(a->data.v);
a->data.v = strdup(name); a->data.v = str_strdup(name);
} }
} }
} }

View file

@ -21,6 +21,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include "raceprefix.h" #include "raceprefix.h"
#include <util/attrib.h> #include <util/attrib.h>
#include <util/strings.h>
#include <assert.h> #include <assert.h>
#include <string.h> #include <string.h>
@ -41,7 +42,7 @@ void set_prefix(attrib ** ap, const char *str)
free(a->data.v); free(a->data.v);
} }
assert(a->type == &at_raceprefix); assert(a->type == &at_raceprefix);
a->data.v = strdup(str); a->data.v = str_strdup(str);
} }
const char *get_prefix(attrib * a) const char *get_prefix(attrib * a)
@ -53,7 +54,7 @@ const char *get_prefix(attrib * a)
str = (char *)a->data.v; str = (char *)a->data.v;
/* conversion of old prefixes */ /* conversion of old prefixes */
if (strncmp(str, "prefix_", 7) == 0) { if (strncmp(str, "prefix_", 7) == 0) {
((attrib *)a)->data.v = strdup(str + 7); ((attrib *)a)->data.v = str_strdup(str + 7);
free(str); free(str);
str = (char *)a->data.v; str = (char *)a->data.v;
} }

View file

@ -21,6 +21,7 @@ without prior permission by the authors of Eressea.
#include <util/log.h> #include <util/log.h>
#include <util/language.h> #include <util/language.h>
#include <util/strings.h>
#include <tolua.h> #include <tolua.h>
#include <stdlib.h> #include <stdlib.h>
@ -84,7 +85,7 @@ static int tolua_building_set_info(lua_State * L)
const char *info = tolua_tostring(L, 2, 0); const char *info = tolua_tostring(L, 2, 0);
free(self->display); free(self->display);
if (info) if (info)
self->display = strdup(info); self->display = str_strdup(info);
else else
self->display = NULL; self->display = NULL;
return 0; return 0;

View file

@ -39,6 +39,7 @@ without prior permission by the authors of Eressea.
#include <util/base36.h> #include <util/base36.h>
#include <util/language.h> #include <util/language.h>
#include <util/log.h> #include <util/log.h>
#include <util/strings.h>
#include <critbit.h> #include <critbit.h>
@ -635,7 +636,7 @@ static int tolua_plane_set_name(lua_State * L)
const char *str = tolua_tostring(L, 2, 0); const char *str = tolua_tostring(L, 2, 0);
free(self->name); free(self->name);
if (str) if (str)
self->name = strdup(str); self->name = str_strdup(str);
else else
self->name = 0; self->name = 0;
return 0; return 0;

View file

@ -25,6 +25,7 @@ without prior permission by the authors of Eressea.
#include <util/attrib.h> #include <util/attrib.h>
#include <util/language.h> #include <util/language.h>
#include <util/log.h> #include <util/log.h>
#include <util/strings.h>
#include <tolua.h> #include <tolua.h>
#include <string.h> #include <string.h>
@ -109,7 +110,7 @@ static int tolua_ship_set_display(lua_State * L)
{ {
ship *self = (ship *)tolua_tousertype(L, 1, NULL); ship *self = (ship *)tolua_tousertype(L, 1, NULL);
free(self->display); free(self->display);
self->display = strdup(tolua_tostring(L, 2, NULL)); self->display = str_strdup(tolua_tostring(L, 2, NULL));
return 0; return 0;
} }

View file

@ -131,7 +131,7 @@ static const char *translate(const char *key, const char *value)
} }
else else
t = malloc(sizeof(translation)); t = malloc(sizeof(translation));
t->key = strdup(key); t->key = str_strdup(key);
t->value = value; t->value = value;
t->next = translation_table[kk]; t->next = translation_table[kk];
translation_table[kk] = t; translation_table[kk] = t;

View file

@ -31,6 +31,7 @@ without prior permission by the authors of Eressea.
#include <util/language.h> #include <util/language.h>
#include <util/parser.h> #include <util/parser.h>
#include <util/rng.h> #include <util/rng.h>
#include <util/strings.h>
#include <util/umlaut.h> #include <util/umlaut.h>
#include <selist.h> #include <selist.h>
@ -83,7 +84,7 @@ alliance *new_alliance(int id, const char *name) {
al = calloc(1, sizeof(alliance)); al = calloc(1, sizeof(alliance));
al->id = id; al->id = id;
if (name) { if (name) {
al->name = strdup(name); al->name = str_strdup(name);
} }
else { else {
al->flags |= ALF_NON_ALLIED; al->flags |= ALF_NON_ALLIED;
@ -434,7 +435,7 @@ void alliance_setname(alliance * self, const char *name)
{ {
free(self->name); free(self->name);
if (name) if (name)
self->name = strdup(name); self->name = str_strdup(name);
else else
self->name = NULL; self->name = NULL;
} }

View file

@ -11,6 +11,7 @@
#include "plane.h" #include "plane.h"
#include <util/attrib.h> #include <util/attrib.h>
#include <util/strings.h>
#include <util/gamedata.h> #include <util/gamedata.h>
#include <storage.h> #include <storage.h>
@ -103,7 +104,7 @@ int AllianceAuto(void)
const char *str = config_get("alliance.auto"); const char *str = config_get("alliance.auto");
value = 0; value = 0;
if (str != NULL) { if (str != NULL) {
char *sstr = strdup(str); char *sstr = str_strdup(str);
char *tok = strtok(sstr, " "); char *tok = strtok(sstr, " ");
while (tok) { while (tok) {
value |= ally_flag(tok, -1); value |= ally_flag(tok, -1);
@ -163,7 +164,7 @@ int HelpMask(void)
if (config_changed(&config)) { if (config_changed(&config)) {
const char *str = config_get("rules.help.mask"); const char *str = config_get("rules.help.mask");
if (str != NULL) { if (str != NULL) {
char *sstr = strdup(str); char *sstr = str_strdup(str);
char *tok = strtok(sstr, " "); char *tok = strtok(sstr, " ");
while (tok) { while (tok) {
rule |= ally_flag(tok, -1); rule |= ally_flag(tok, -1);
@ -183,7 +184,7 @@ static int AllianceRestricted(void)
const char *str = config_get("alliance.restricted"); const char *str = config_get("alliance.restricted");
int rule = 0; int rule = 0;
if (str != NULL) { if (str != NULL) {
char *sstr = strdup(str); char *sstr = str_strdup(str);
char *tok = strtok(sstr, " "); char *tok = strtok(sstr, " ");
while (tok) { while (tok) {
rule |= ally_flag(tok, -1); rule |= ally_flag(tok, -1);

View file

@ -44,6 +44,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <util/language.h> #include <util/language.h>
#include <util/log.h> #include <util/log.h>
#include <util/resolve.h> #include <util/resolve.h>
#include <util/strings.h>
#include <util/umlaut.h> #include <util/umlaut.h>
#include <storage.h> #include <storage.h>
@ -134,7 +135,7 @@ building_type *bt_get_or_create(const char *name)
building_type *btype = bt_find_i(name); building_type *btype = bt_find_i(name);
if (btype == NULL) { if (btype == NULL) {
btype = calloc(sizeof(building_type), 1); btype = calloc(sizeof(building_type), 1);
btype->_name = strdup(name); btype->_name = str_strdup(name);
btype->auraregen = 1.0; btype->auraregen = 1.0;
btype->maxsize = -1; btype->maxsize = -1;
btype->capacity = 1; btype->capacity = 1;
@ -373,7 +374,7 @@ building *new_building(const struct building_type * btype, region * r,
} }
assert(bname); assert(bname);
snprintf(buffer, sizeof(buffer), "%s %s", bname, itoa36(b->no)); snprintf(buffer, sizeof(buffer), "%s %s", bname, itoa36(b->no));
b->name = strdup(bname); b->name = str_strdup(bname);
return b; return b;
} }
@ -569,7 +570,7 @@ void building_setname(building * self, const char *name)
{ {
free(self->name); free(self->name);
if (name) if (name)
self->name = strdup(name); self->name = str_strdup(name);
else else
self->name = NULL; self->name = NULL;
} }

View file

@ -7,6 +7,7 @@
#include <kernel/unit.h> #include <kernel/unit.h>
#include <util/language.h> #include <util/language.h>
#include <util/strings.h>
#include <CuTest.h> #include <CuTest.h>
#include <tests.h> #include <tests.h>
@ -564,7 +565,7 @@ static void test_buildingtype(CuTest *tc) {
btype = test_create_buildingtype("hodor"); btype = test_create_buildingtype("hodor");
CuAssertPtrNotNull(tc, btype->construction); CuAssertPtrNotNull(tc, btype->construction);
CuAssertStrEquals(tc, "hodor", buildingtype(btype, NULL, 1)); CuAssertStrEquals(tc, "hodor", buildingtype(btype, NULL, 1));
btype->construction->name = strdup("castle"); btype->construction->name = str_strdup("castle");
CuAssertStrEquals(tc, "castle", buildingtype(btype, NULL, 1)); CuAssertStrEquals(tc, "castle", buildingtype(btype, NULL, 1));
btype = bt_get_or_create("portal"); btype = bt_get_or_create("portal");
CuAssertPtrEquals(tc, NULL, btype->construction); CuAssertPtrEquals(tc, NULL, btype->construction);

View file

@ -65,6 +65,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <util/parser.h> #include <util/parser.h>
#include <util/rand.h> #include <util/rand.h>
#include <util/rng.h> #include <util/rng.h>
#include <util/strings.h>
#include <util/translation.h> #include <util/translation.h>
#include <util/umlaut.h> #include <util/umlaut.h>
#include <util/xml.h> #include <util/xml.h>
@ -381,7 +382,7 @@ static void init_magic(struct locale *lang)
str = "gwyrrd illaun draig cerddor tybied"; str = "gwyrrd illaun draig cerddor tybied";
} }
sstr = strdup(str); sstr = str_strdup(str);
tok = strtok(sstr, " "); tok = strtok(sstr, " ");
while (tok) { while (tok) {
variant var; variant var;
@ -488,7 +489,7 @@ int check_param(const struct param *p, const char *key, const char *searchvalue)
if (!value) { if (!value) {
return 0; return 0;
} }
p_value = strdup(value); p_value = str_strdup(value);
v = strtok(p_value, " ,;"); v = strtok(p_value, " ,;");
while (v != NULL) { while (v != NULL) {

View file

@ -33,6 +33,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <util/log.h> #include <util/log.h>
#include <util/rand.h> #include <util/rand.h>
#include <util/rng.h> #include <util/rng.h>
#include <util/strings.h>
/* libc includes */ /* libc includes */
#include <assert.h> #include <assert.h>
@ -43,7 +44,7 @@ void equipment_setskill(equipment * eq, skill_t sk, const char *value)
{ {
if (eq != NULL) { if (eq != NULL) {
if (value != NULL) { if (value != NULL) {
eq->skills[sk] = strdup(value); eq->skills[sk] = str_strdup(value);
} }
else if (eq->skills[sk]) { else if (eq->skills[sk]) {
free(eq->skills[sk]); free(eq->skills[sk]);
@ -78,7 +79,7 @@ equipment_setitem(equipment * eq, const item_type * itype, const char *value)
if (idata == NULL) { if (idata == NULL) {
idata = (itemdata *)malloc(sizeof(itemdata)); idata = (itemdata *)malloc(sizeof(itemdata));
idata->itype = itype; idata->itype = itype;
idata->value = strdup(value); idata->value = str_strdup(value);
idata->next = eq->items; idata->next = eq->items;
eq->items = idata; eq->items = idata;
} }

View file

@ -264,7 +264,7 @@ faction *addfaction(const char *email, const char *password,
fhash(f); fhash(f);
slprintf(buf, sizeof(buf), "%s %s", LOC(loc, "factiondefault"), itoa36(f->no)); slprintf(buf, sizeof(buf), "%s %s", LOC(loc, "factiondefault"), itoa36(f->no));
f->name = strdup(buf); f->name = str_strdup(buf);
if (!f->race) { if (!f->race) {
log_warning("creating a faction that has no race", itoa36(f->no)); log_warning("creating a faction that has no race", itoa36(f->no));
@ -597,7 +597,7 @@ void faction_setname(faction * self, const char *name)
{ {
free(self->name); free(self->name);
if (name) if (name)
self->name = strdup(name); self->name = str_strdup(name);
} }
const char *faction_getemail(const faction * self) const char *faction_getemail(const faction * self)
@ -609,7 +609,7 @@ void faction_setemail(faction * self, const char *email)
{ {
free(self->email); free(self->email);
if (email) if (email)
self->email = strdup(email); self->email = str_strdup(email);
else else
self->email = NULL; self->email = NULL;
} }
@ -623,14 +623,14 @@ void faction_setbanner(faction * self, const char *banner)
{ {
free(self->banner); free(self->banner);
if (banner) if (banner)
self->banner = strdup(banner); self->banner = str_strdup(banner);
} }
void faction_setpassword(faction * f, const char *pwhash) void faction_setpassword(faction * f, const char *pwhash)
{ {
assert(pwhash); assert(pwhash);
free(f->_password); free(f->_password);
f->_password = strdup(pwhash); f->_password = str_strdup(pwhash);
} }
bool valid_race(const struct faction *f, const struct race *rc) bool valid_race(const struct faction *f, const struct race *rc)

View file

@ -34,6 +34,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <util/base36.h> #include <util/base36.h>
#include <util/gamedata.h> #include <util/gamedata.h>
#include <util/resolve.h> #include <util/resolve.h>
#include <util/strings.h>
#include <util/unicode.h> #include <util/unicode.h>
#include <storage.h> #include <storage.h>
@ -59,7 +60,7 @@ group *new_group(faction * f, const char *name, int gid)
*gp = g; *gp = g;
maxgid = MAX(gid, maxgid); maxgid = MAX(gid, maxgid);
g->name = strdup(name); g->name = str_strdup(name);
g->gid = gid; g->gid = gid;
g->nexthash = ghash[index]; g->nexthash = ghash[index];

View file

@ -43,6 +43,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <util/language.h> #include <util/language.h>
#include <util/message.h> #include <util/message.h>
#include <util/rng.h> #include <util/rng.h>
#include <util/strings.h>
#include <util/umlaut.h> #include <util/umlaut.h>
#include <critbit.h> #include <critbit.h>
@ -196,7 +197,7 @@ resource_type *rt_get_or_create(const char *name) {
perror("resource_type allocation failed"); perror("resource_type allocation failed");
} }
else { else {
rtype->_name = strdup(name); rtype->_name = str_strdup(name);
rt_register(rtype); rt_register(rtype);
} }
} }
@ -279,8 +280,8 @@ weapon_type *new_weapontype(item_type * itype,
wtype = calloc(sizeof(weapon_type), 1); wtype = calloc(sizeof(weapon_type), 1);
if (damage) { if (damage) {
wtype->damage[0] = strdup(damage[0]); wtype->damage[0] = str_strdup(damage[0]);
wtype->damage[1] = strdup(damage[1]); wtype->damage[1] = str_strdup(damage[1]);
} }
wtype->defmod = defmod; wtype->defmod = defmod;
wtype->flags |= wflags; wtype->flags |= wflags;
@ -339,9 +340,9 @@ void it_set_appearance(item_type *itype, const char *appearance) {
assert(itype->rtype); assert(itype->rtype);
if (appearance) { if (appearance) {
char plural[32]; char plural[32];
itype->_appearance[0] = strdup(appearance); itype->_appearance[0] = str_strdup(appearance);
snprintf(plural, sizeof(plural), "%s_p", appearance); snprintf(plural, sizeof(plural), "%s_p", appearance);
itype->_appearance[1] = strdup(plural); itype->_appearance[1] = str_strdup(plural);
} else { } else {
itype->_appearance[0] = 0; itype->_appearance[0] = 0;
itype->_appearance[1] = 0; itype->_appearance[1] = 0;

View file

@ -45,6 +45,7 @@ without prior permission by the authors of Eressea.
#include <util/log.h> #include <util/log.h>
#include <util/message.h> #include <util/message.h>
#include <util/nrmessage.h> #include <util/nrmessage.h>
#include <util/strings.h>
#include <util/xml.h> #include <util/xml.h>
/* external libraries */ /* external libraries */
@ -228,7 +229,7 @@ static void json_terrain_production(cJSON *json, terrain_production *prod) {
if (dst) { if (dst) {
free(*dst); free(*dst);
assert(child->type == cJSON_String); assert(child->type == cJSON_String);
*dst = strdup(child->valuestring); *dst = str_strdup(child->valuestring);
} }
} }
} }
@ -452,7 +453,7 @@ static void json_race(cJSON *json, race *rc) {
switch (child->type) { switch (child->type) {
case cJSON_String: case cJSON_String:
if (strcmp(child->string, "damage") == 0) { if (strcmp(child->string, "damage") == 0) {
rc->def_damage = strdup(child->valuestring); rc->def_damage = str_strdup(child->valuestring);
} }
break; break;
case cJSON_Number: case cJSON_Number:
@ -592,7 +593,7 @@ static void json_spells(cJSON *json) {
continue; continue;
} }
else if (strcmp(item->string, "syntax") == 0) { else if (strcmp(item->string, "syntax") == 0) {
sp->syntax = strdup(item->valuestring); sp->syntax = str_strdup(item->valuestring);
} }
} }
} }
@ -703,7 +704,7 @@ static void json_calendar(cJSON *json) {
weeknames = malloc(sizeof(char *) * weeks_per_month); weeknames = malloc(sizeof(char *) * weeks_per_month);
for (i = 0, entry = child->child; entry; entry = entry->next, ++i) { for (i = 0, entry = child->child; entry; entry = entry->next, ++i) {
if (entry->type == cJSON_String) { if (entry->type == cJSON_String) {
weeknames[i] = strdup(entry->valuestring); weeknames[i] = str_strdup(entry->valuestring);
} }
else { else {
log_error("calendar.weeks[%d] is not a string: %d", i, json->type); log_error("calendar.weeks[%d] is not a string: %d", i, json->type);

View file

@ -27,6 +27,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
/* util includes */ /* util includes */
#include <util/attrib.h> #include <util/attrib.h>
#include <util/resolve.h> #include <util/resolve.h>
#include <util/strings.h>
#include <util/lists.h> #include <util/lists.h>
#include <storage.h> #include <storage.h>
@ -234,7 +235,7 @@ plane *create_new_plane(int id, const char *name, int minx, int maxx, int miny,
pl->next = NULL; pl->next = NULL;
pl->id = id; pl->id = id;
if (name) if (name)
pl->name = strdup(name); pl->name = str_strdup(name);
pl->minx = minx; pl->minx = minx;
pl->maxx = maxx; pl->maxx = maxx;
pl->miny = miny; pl->miny = miny;

View file

@ -44,6 +44,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <util/language.h> #include <util/language.h>
#include <util/log.h> #include <util/log.h>
#include <util/rng.h> #include <util/rng.h>
#include <util/strings.h>
#include <util/variant.h> #include <util/variant.h>
#include <storage.h> #include <storage.h>
@ -132,7 +133,7 @@ static void rc_setoption(race *rc, int k, const char *value) {
v->v = rc_get_or_create(value); v->v = rc_get_or_create(value);
} }
else if (key == RCO_HUNGER) { else if (key == RCO_HUNGER) {
v->v = strdup(value); v->v = str_strdup(value);
} }
else if (key == RCO_TRADEHERB) { else if (key == RCO_TRADEHERB) {
v->i = atoi(value); v->i = atoi(value);
@ -359,7 +360,7 @@ race *rc_create(const char *zName)
log_error("race '%s' has an invalid name. remove spaces\n", zName); log_error("race '%s' has an invalid name. remove spaces\n", zName);
assert(strchr(zName, ' ') == NULL); assert(strchr(zName, ' ') == NULL);
} }
rc->_name = strdup(zName); rc->_name = str_strdup(zName);
rc->attack[0].type = AT_COMBATSPELL; rc->attack[0].type = AT_COMBATSPELL;
for (i = 1; i < RACE_ATTACKS; ++i) for (i = 1; i < RACE_ATTACKS; ++i)

View file

@ -52,6 +52,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <util/language.h> #include <util/language.h>
#include <util/rand.h> #include <util/rand.h>
#include <util/rng.h> #include <util/rng.h>
#include <util/strings.h>
#include <storage.h> #include <storage.h>
@ -1419,7 +1420,7 @@ void region_setinfo(struct region *r, const char *info)
{ {
assert(r->land); assert(r->land);
free(r->land->display); free(r->land->display);
r->land->display = (info && info[0]) ? strdup(info) : 0; r->land->display = (info && info[0]) ? str_strdup(info) : 0;
} }
const char *region_getinfo(const region * r) const char *region_getinfo(const region * r)
@ -1431,7 +1432,7 @@ void region_setname(struct region *r, const char *name)
{ {
if (r->land) { if (r->land) {
free(r->land->name); free(r->land->name);
r->land->name = name ? strdup(name) : 0; r->land->name = name ? str_strdup(name) : 0;
} }
} }

View file

@ -73,6 +73,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <util/rand.h> #include <util/rand.h>
#include <util/resolve.h> #include <util/resolve.h>
#include <util/rng.h> #include <util/rng.h>
#include <util/strings.h>
#include <util/umlaut.h> #include <util/umlaut.h>
#include <util/unicode.h> #include <util/unicode.h>
@ -157,7 +158,7 @@ void read_planes(gamedata *data) {
} }
pl->id = id; pl->id = id;
READ_STR(store, name, sizeof(name)); READ_STR(store, name, sizeof(name));
pl->name = strdup(name); pl->name = str_strdup(name);
READ_INT(store, &pl->minx); READ_INT(store, &pl->minx);
READ_INT(store, &pl->maxx); READ_INT(store, &pl->maxx);
READ_INT(store, &pl->miny); READ_INT(store, &pl->miny);
@ -421,12 +422,12 @@ unit *read_unit(gamedata *data)
if (unicode_utf8_trim(obuf)!=0) { if (unicode_utf8_trim(obuf)!=0) {
log_warning("trim unit %s name to '%s'", itoa36(u->no), obuf); log_warning("trim unit %s name to '%s'", itoa36(u->no), obuf);
} }
u->_name = obuf[0] ? strdup(obuf) : 0; u->_name = obuf[0] ? str_strdup(obuf) : 0;
READ_STR(data->store, obuf, sizeof(obuf)); READ_STR(data->store, obuf, sizeof(obuf));
if (unicode_utf8_trim(obuf)!=0) { if (unicode_utf8_trim(obuf)!=0) {
log_warning("trim unit %s info to '%s'", itoa36(u->no), obuf); log_warning("trim unit %s info to '%s'", itoa36(u->no), obuf);
} }
u->display = obuf[0] ? strdup(obuf) : 0; u->display = obuf[0] ? str_strdup(obuf) : 0;
READ_INT(data->store, &number); READ_INT(data->store, &number);
set_number(u, number); set_number(u, number);
@ -648,7 +649,7 @@ static region *readregion(gamedata *data, int x, int y)
if (unicode_utf8_trim(name) != 0) { if (unicode_utf8_trim(name) != 0) {
log_warning("trim region %d name to '%s'", uid, name); log_warning("trim region %d name to '%s'", uid, name);
}; };
r->land->name = strdup(name); r->land->name = str_strdup(name);
} }
if (r->land) { if (r->land) {
int i; int i;
@ -888,7 +889,7 @@ static char * getpasswd(int fno) {
assert(line[slen] == '\n'); assert(line[slen] == '\n');
line[slen] = 0; line[slen] = 0;
fclose(F); fclose(F);
return strdup(line + len + 1); return str_strdup(line + len + 1);
} }
} }
fclose(F); fclose(F);
@ -980,12 +981,12 @@ faction *read_faction(gamedata * data)
if (unicode_utf8_trim(name)!=0) { if (unicode_utf8_trim(name)!=0) {
log_warning("trim faction %s name to '%s'", itoa36(f->no), name); log_warning("trim faction %s name to '%s'", itoa36(f->no), name);
}; };
f->name = strdup(name); f->name = str_strdup(name);
READ_STR(data->store, name, sizeof(name)); READ_STR(data->store, name, sizeof(name));
if (unicode_utf8_trim(name)!=0) { if (unicode_utf8_trim(name)!=0) {
log_warning("trim faction %s banner to '%s'", itoa36(f->no), name); log_warning("trim faction %s banner to '%s'", itoa36(f->no), name);
}; };
f->banner = strdup(name); f->banner = str_strdup(name);
log_debug(" - Lese Partei %s (%s)", f->name, itoa36(f->no)); log_debug(" - Lese Partei %s (%s)", f->name, itoa36(f->no));
@ -1210,12 +1211,12 @@ struct building *read_building(gamedata *data) {
if (unicode_utf8_trim(name)!=0) { if (unicode_utf8_trim(name)!=0) {
log_warning("trim building %s name to '%s'", itoa36(b->no), name); log_warning("trim building %s name to '%s'", itoa36(b->no), name);
} }
b->name = strdup(name); b->name = str_strdup(name);
READ_STR(store, name, sizeof(name)); READ_STR(store, name, sizeof(name));
if (unicode_utf8_trim(name)!=0) { if (unicode_utf8_trim(name)!=0) {
log_warning("trim building %s info to '%s'", itoa36(b->no), name); log_warning("trim building %s info to '%s'", itoa36(b->no), name);
} }
b->display = strdup(name); b->display = str_strdup(name);
READ_INT(store, &b->size); READ_INT(store, &b->size);
READ_STR(store, name, sizeof(name)); READ_STR(store, name, sizeof(name));
b->type = bt_find(name); b->type = bt_find(name);
@ -1264,12 +1265,12 @@ ship *read_ship(gamedata *data)
if (unicode_utf8_trim(name)!=0) { if (unicode_utf8_trim(name)!=0) {
log_warning("trim ship %s name to '%s'", itoa36(sh->no), name); log_warning("trim ship %s name to '%s'", itoa36(sh->no), name);
} }
sh->name = strdup(name); sh->name = str_strdup(name);
READ_STR(store, name, sizeof(name)); READ_STR(store, name, sizeof(name));
if (unicode_utf8_trim(name)!=0) { if (unicode_utf8_trim(name)!=0) {
log_warning("trim ship %s info to '%s'", itoa36(sh->no), name); log_warning("trim ship %s info to '%s'", itoa36(sh->no), name);
} }
sh->display = strdup(name); sh->display = str_strdup(name);
READ_STR(store, name, sizeof(name)); READ_STR(store, name, sizeof(name));
sh->type = st_find(name); sh->type = st_find(name);
if (sh->type == NULL) { if (sh->type == NULL) {

View file

@ -1,8 +1,6 @@
#include <platform.h> #include <platform.h>
#include <kernel/config.h> #include <kernel/config.h>
#include <kernel/race.h> #include <kernel/race.h>
#include <util/attrib.h>
#include <util/gamedata.h>
#include <attributes/key.h> #include <attributes/key.h>
#include "save.h" #include "save.h"
@ -20,9 +18,11 @@
#include <triggers/createunit.h> #include <triggers/createunit.h>
#include <triggers/timeout.h> #include <triggers/timeout.h>
#include <util/attrib.h> #include <util/attrib.h>
#include <util/event.h>
#include <util/base36.h> #include <util/base36.h>
#include <util/event.h>
#include <util/gamedata.h>
#include <util/password.h> #include <util/password.h>
#include <util/strings.h>
#include <storage.h> #include <storage.h>
#include <memstream.h> #include <memstream.h>
@ -100,7 +100,7 @@ static void test_readwrite_faction(CuTest * tc)
test_setup(); test_setup();
f = test_create_faction(0); f = test_create_faction(0);
free(f->name); free(f->name);
f->name = strdup(" Hodor "); f->name = str_strdup(" Hodor ");
CuAssertStrEquals(tc, " Hodor ", f->name); CuAssertStrEquals(tc, " Hodor ", f->name);
mstream_init(&data.strm); mstream_init(&data.strm);
gamedata_init(&data, &store, RELEASE_VERSION); gamedata_init(&data, &store, RELEASE_VERSION);
@ -130,7 +130,7 @@ static void test_readwrite_region(CuTest * tc)
test_setup(); test_setup();
r = test_create_region(0, 0, 0); r = test_create_region(0, 0, 0);
free(r->land->name); free(r->land->name);
r->land->name = strdup(" Hodor "); r->land->name = str_strdup(" Hodor ");
CuAssertStrEquals(tc, " Hodor ", r->land->name); CuAssertStrEquals(tc, " Hodor ", r->land->name);
region_setinfo(r, lipsum); region_setinfo(r, lipsum);
CuAssertStrEquals(tc, lipsum, r->land->display); CuAssertStrEquals(tc, lipsum, r->land->display);
@ -163,7 +163,7 @@ static void test_readwrite_building(CuTest * tc)
r = test_create_region(0, 0, 0); r = test_create_region(0, 0, 0);
b = test_create_building(r, 0); b = test_create_building(r, 0);
free(b->name); free(b->name);
b->name = strdup(" Hodor "); b->name = str_strdup(" Hodor ");
CuAssertStrEquals(tc, " Hodor ", b->name); CuAssertStrEquals(tc, " Hodor ", b->name);
mstream_init(&data.strm); mstream_init(&data.strm);
gamedata_init(&data, &store, RELEASE_VERSION); gamedata_init(&data, &store, RELEASE_VERSION);
@ -196,7 +196,7 @@ static void test_readwrite_ship(CuTest * tc)
r = test_create_region(0, 0, 0); r = test_create_region(0, 0, 0);
sh = test_create_ship(r, 0); sh = test_create_ship(r, 0);
free(sh->name); free(sh->name);
sh->name = strdup(" Hodor "); sh->name = str_strdup(" Hodor ");
CuAssertStrEquals(tc, " Hodor ", sh->name); CuAssertStrEquals(tc, " Hodor ", sh->name);
mstream_init(&data.strm); mstream_init(&data.strm);
gamedata_init(&data, &store, RELEASE_VERSION); gamedata_init(&data, &store, RELEASE_VERSION);

View file

@ -40,6 +40,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <util/language.h> #include <util/language.h>
#include <util/lists.h> #include <util/lists.h>
#include <util/log.h> #include <util/log.h>
#include <util/strings.h>
#include <util/umlaut.h> #include <util/umlaut.h>
#include <util/xml.h> #include <util/xml.h>
@ -124,7 +125,7 @@ ship_type *st_get_or_create(const char * name) {
assert(!snames); assert(!snames);
if (!st) { if (!st) {
st = (ship_type *)calloc(sizeof(ship_type), 1); st = (ship_type *)calloc(sizeof(ship_type), 1);
st->_name = strdup(name); st->_name = str_strdup(name);
st->storm = 1.0; st->storm = 1.0;
st_register(st); st_register(st);
} }
@ -217,7 +218,7 @@ ship *new_ship(const ship_type * stype, region * r, const struct locale *lang)
} }
assert(sname); assert(sname);
snprintf(buffer, sizeof(buffer), "%s %s", sname, itoa36(sh->no)); snprintf(buffer, sizeof(buffer), "%s %s", sname, itoa36(sh->no));
sh->name = strdup(buffer); sh->name = str_strdup(buffer);
shash(sh); shash(sh);
if (r) { if (r) {
addlist(&r->ships, sh); addlist(&r->ships, sh);
@ -491,7 +492,7 @@ void write_ship_reference(const struct ship *sh, struct storage *store)
void ship_setname(ship * self, const char *name) void ship_setname(ship * self, const char *name)
{ {
free(self->name); free(self->name);
self->name = name ? strdup(name) : 0; self->name = name ? str_strdup(name) : 0;
} }
const char *ship_getname(const ship * self) const char *ship_getname(const ship * self)

View file

@ -25,6 +25,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <util/strings.h> #include <util/strings.h>
#include <util/language.h> #include <util/language.h>
#include <util/log.h> #include <util/log.h>
#include <util/strings.h>
#include <util/umlaut.h> #include <util/umlaut.h>
#include <selist.h> #include <selist.h>
@ -124,7 +125,7 @@ spell * create_spell(const char * name)
sp = (spell *)calloc(1, sizeof(spell)); sp = (spell *)calloc(1, sizeof(spell));
len = cb_new_kv(name, len, &sp, sizeof(sp), buffer); len = cb_new_kv(name, len, &sp, sizeof(sp), buffer);
if (cb_insert(&cb_spells, buffer, len) == CB_SUCCESS) { if (cb_insert(&cb_spells, buffer, len) == CB_SUCCESS) {
sp->sname = strdup(name); sp->sname = str_strdup(name);
add_spell(&spells, sp); add_spell(&spells, sp);
return sp; return sp;
} }
@ -173,10 +174,10 @@ struct spellref *spellref_create(spell *sp, const char *name)
if (sp) { if (sp) {
spref->sp = sp; spref->sp = sp;
spref->name = strdup(sp->sname); spref->name = str_strdup(sp->sname);
} }
else if (name) { else if (name) {
spref->name = strdup(name); spref->name = str_strdup(name);
spref->sp = NULL; spref->sp = NULL;
} }
return spref; return spref;

View file

@ -1,12 +1,13 @@
#include <platform.h>
#include <kernel/config.h> #include <kernel/config.h>
#include <kernel/spell.h> #include <kernel/spell.h>
#include <selist.h>
#include <util/log.h> #include <util/log.h>
#include <util/gamedata.h> #include <util/gamedata.h>
#include <util/strings.h>
#include "spellbook.h" #include "spellbook.h"
#include <selist.h>
#include <storage.h> #include <storage.h>
#include <assert.h> #include <assert.h>
@ -16,7 +17,7 @@
spellbook * create_spellbook(const char * name) spellbook * create_spellbook(const char * name)
{ {
spellbook *result = (spellbook *)malloc(sizeof(spellbook)); spellbook *result = (spellbook *)malloc(sizeof(spellbook));
result->name = name ? strdup(name) : 0; result->name = name ? str_strdup(name) : 0;
result->spells = 0; result->spells = 0;
return result; return result;
} }

View file

@ -31,6 +31,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <util/log.h> #include <util/log.h>
#include <util/attrib.h> #include <util/attrib.h>
#include <util/strings.h>
/* libc includes */ /* libc includes */
#include <assert.h> #include <assert.h>
@ -123,7 +124,7 @@ terrain_type * get_or_create_terrain(const char *name) {
++terrain_changes; ++terrain_changes;
terrain = (terrain_type *)calloc(sizeof(terrain_type), 1); terrain = (terrain_type *)calloc(sizeof(terrain_type), 1);
if (terrain) { if (terrain) {
terrain->_name = strdup(name); terrain->_name = str_strdup(name);
terrain->next = registered_terrains; terrain->next = registered_terrains;
registered_terrains = terrain; registered_terrains = terrain;
if (strcmp("plain", name) == 0) { if (strcmp("plain", name) == 0) {

View file

@ -61,6 +61,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <util/rand.h> #include <util/rand.h>
#include <util/resolve.h> #include <util/resolve.h>
#include <util/rng.h> #include <util/rng.h>
#include <util/strings.h>
#include <util/variant.h> #include <util/variant.h>
#include <storage.h> #include <storage.h>
@ -509,7 +510,7 @@ int a_readprivate(attrib * a, void *owner, gamedata *data)
struct storage *store = data->store; struct storage *store = data->store;
char lbuf[DISPLAYSIZE]; char lbuf[DISPLAYSIZE];
READ_STR(store, lbuf, sizeof(lbuf)); READ_STR(store, lbuf, sizeof(lbuf));
a->data.v = strdup(lbuf); a->data.v = str_strdup(lbuf);
return (a->data.v) ? AT_READ_OK : AT_READ_FAIL; return (a->data.v) ? AT_READ_OK : AT_READ_FAIL;
} }
@ -567,7 +568,7 @@ void usetprivate(unit * u, const char *str)
if (a->data.v) { if (a->data.v) {
free(a->data.v); free(a->data.v);
} }
a->data.v = strdup(str); a->data.v = str_strdup(str);
} }
/*********************/ /*********************/
@ -1512,7 +1513,7 @@ unit *create_unit(region * r, faction * f, int number, const struct race *urace,
} }
if (dname) { if (dname) {
u->_name = strdup(dname); u->_name = str_strdup(dname);
} }
else if (urace->name_unit || playerrace(urace)) { else if (urace->name_unit || playerrace(urace)) {
name_unit(u); name_unit(u);
@ -1615,7 +1616,7 @@ void unit_setname(unit * u, const char *name)
{ {
free(u->_name); free(u->_name);
if (name && name[0]) if (name && name[0])
u->_name = strdup(name); u->_name = str_strdup(name);
else else
u->_name = NULL; u->_name = NULL;
} }
@ -1629,7 +1630,7 @@ void unit_setinfo(unit * u, const char *info)
{ {
free(u->display); free(u->display);
if (info) if (info)
u->display = strdup(info); u->display = str_strdup(info);
else else
u->display = NULL; u->display = NULL;
} }

View file

@ -13,6 +13,7 @@
#include <util/base36.h> #include <util/base36.h>
#include <util/language.h> #include <util/language.h>
#include <util/rng.h> #include <util/rng.h>
#include <util/strings.h>
#include <spells/regioncurse.h> #include <spells/regioncurse.h>
#include <alchemy.h> #include <alchemy.h>
#include <laws.h> #include <laws.h>
@ -397,7 +398,7 @@ static void test_unit_description(CuTest *tc) {
CuAssertPtrEquals(tc, 0, u->display); CuAssertPtrEquals(tc, 0, u->display);
CuAssertStrEquals(tc, 0, u_description(u, lang)); CuAssertStrEquals(tc, 0, u_description(u, lang));
u->display = strdup("Hodor"); u->display = str_strdup("Hodor");
CuAssertStrEquals(tc, "Hodor", u_description(u, NULL)); CuAssertStrEquals(tc, "Hodor", u_description(u, NULL));
CuAssertStrEquals(tc, "Hodor", u_description(u, lang)); CuAssertStrEquals(tc, "Hodor", u_description(u, lang));

View file

@ -46,6 +46,7 @@ without prior permission by the authors of Eressea.
#include <util/log.h> #include <util/log.h>
#include <util/message.h> #include <util/message.h>
#include <util/nrmessage.h> #include <util/nrmessage.h>
#include <util/strings.h>
#include <util/xml.h> #include <util/xml.h>
/* libxml includes */ /* libxml includes */
@ -248,7 +249,7 @@ construction ** consPtr, construct_t type)
if (type == CONS_BUILDING) { if (type == CONS_BUILDING) {
propValue = xmlGetProp(node, BAD_CAST "name"); propValue = xmlGetProp(node, BAD_CAST "name");
if (propValue != NULL) { if (propValue != NULL) {
con->name = strdup((const char *)propValue); con->name = str_strdup((const char *)propValue);
xmlFree(propValue); xmlFree(propValue);
} }
} }
@ -573,7 +574,7 @@ static weapon_type *xml_readweapon(xmlXPathContextPtr xpath, item_type * itype)
xmlFree(propValue); xmlFree(propValue);
propValue = xmlGetProp(node, BAD_CAST "value"); propValue = xmlGetProp(node, BAD_CAST "value");
wtype->damage[pos] = strdup((const char *)propValue); /* TODO: this is a memory leak */ wtype->damage[pos] = str_strdup((const char *)propValue); /* TODO: this is a memory leak */
if (k == 0) if (k == 0)
wtype->damage[1 - pos] = wtype->damage[pos]; wtype->damage[1 - pos] = wtype->damage[pos];
xmlFree(propValue); xmlFree(propValue);
@ -1200,13 +1201,13 @@ static int parse_spells(xmlDocPtr doc)
propValue = xmlGetProp(node, BAD_CAST "parameters"); propValue = xmlGetProp(node, BAD_CAST "parameters");
if (propValue) { if (propValue) {
sp->parameter = strdup((const char *)propValue); sp->parameter = str_strdup((const char *)propValue);
xmlFree(propValue); xmlFree(propValue);
} }
propValue = xmlGetProp(node, BAD_CAST "syntax"); propValue = xmlGetProp(node, BAD_CAST "syntax");
if (propValue) { if (propValue) {
sp->syntax = strdup((const char *)propValue); sp->syntax = str_strdup((const char *)propValue);
xmlFree(propValue); xmlFree(propValue);
} }
#ifdef TODO /* no longer need it, spellbooks! */ #ifdef TODO /* no longer need it, spellbooks! */
@ -1355,7 +1356,7 @@ static int parse_races(xmlDocPtr doc)
propValue = xmlGetProp(node, BAD_CAST "damage"); propValue = xmlGetProp(node, BAD_CAST "damage");
assert(propValue != NULL); assert(propValue != NULL);
rc->def_damage = strdup((const char *)propValue); rc->def_damage = str_strdup((const char *)propValue);
xmlFree(propValue); xmlFree(propValue);
rc->magres = frac_make(xml_ivalue(node, "magres", 100), 100); rc->magres = frac_make(xml_ivalue(node, "magres", 100), 100);
@ -1550,7 +1551,7 @@ static int parse_races(xmlDocPtr doc)
propValue = xmlGetProp(node, BAD_CAST "damage"); propValue = xmlGetProp(node, BAD_CAST "damage");
if (propValue != NULL) { if (propValue != NULL) {
attack->data.dice = strdup((const char *)propValue); attack->data.dice = str_strdup((const char *)propValue);
xmlFree(propValue); xmlFree(propValue);
} }
else { else {
@ -1613,7 +1614,7 @@ static int parse_messages(xmlDocPtr doc)
(const char *)propType); (const char *)propType);
xmlFree(propName); xmlFree(propName);
xmlFree(propType); xmlFree(propType);
argv[k] = strdup(zBuffer); argv[k] = str_strdup(zBuffer);
} }
argv[result->nodesetval->nodeNr] = NULL; argv[result->nodesetval->nodeNr] = NULL;
} }

View file

@ -1586,7 +1586,7 @@ int display_cmd(unit * u, struct order *ord)
free(*s); free(*s);
if (s2) { if (s2) {
char * str = strdup(s2); char * str = str_strdup(s2);
if (unicode_utf8_trim(str) != 0) { if (unicode_utf8_trim(str) != 0) {
log_info("trimming info: %s", s2); log_info("trimming info: %s", s2);
} }
@ -1636,7 +1636,7 @@ static int rename_cmd(unit * u, order * ord, char **s, const char *s2)
} }
free(*s); free(*s);
*s = strdup(name); *s = str_strdup(name);
return 0; return 0;
} }
@ -2119,7 +2119,7 @@ int banner_cmd(unit * u, struct order *ord)
free(u->faction->banner); free(u->faction->banner);
init_order_depr(ord); init_order_depr(ord);
s = getstrtoken(); s = getstrtoken();
u->faction->banner = s ? strdup(s) : 0; u->faction->banner = s ? str_strdup(s) : 0;
add_message(&u->faction->msgs, msg_message("changebanner", "value", add_message(&u->faction->msgs, msg_message("changebanner", "value",
u->faction->banner)); u->faction->banner));

View file

@ -17,6 +17,7 @@
#include "gmtool_structs.h" #include "gmtool_structs.h"
#include <util/log.h> #include <util/log.h>
#include <util/strings.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@ -27,7 +28,7 @@ insert_selection(list_selection ** p_sel, list_selection * prev,
const char *str, void *payload) const char *str, void *payload)
{ {
list_selection *sel = calloc(sizeof(list_selection), 1); list_selection *sel = calloc(sizeof(list_selection), 1);
sel->str = strdup(str); sel->str = str_strdup(str);
sel->data = payload; sel->data = payload;
if (*p_sel) { if (*p_sel) {
list_selection *s; list_selection *s;

View file

@ -17,7 +17,6 @@ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
**/ **/
#include <platform.h>
#include <kernel/config.h> #include <kernel/config.h>
#include "magic.h" #include "magic.h"
@ -61,19 +60,20 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
/* util includes */ /* util includes */
#include <util/attrib.h> #include <util/attrib.h>
#include <util/base36.h>
#include <util/event.h>
#include <util/gamedata.h> #include <util/gamedata.h>
#include <util/language.h> #include <util/language.h>
#include <util/lists.h> #include <util/lists.h>
#include <util/log.h> #include <util/log.h>
#include <util/parser.h> #include <util/parser.h>
#include <selist.h>
#include <util/resolve.h>
#include <util/rand.h> #include <util/rand.h>
#include <util/resolve.h>
#include <util/rng.h> #include <util/rng.h>
#include <util/strings.h>
#include <util/umlaut.h> #include <util/umlaut.h>
#include <util/base36.h>
#include <util/event.h>
#include <selist.h>
#include <critbit.h> #include <critbit.h>
#include <storage.h> #include <storage.h>
@ -126,7 +126,7 @@ static double MagicPower(double force)
if (force > 0) { if (force > 0) {
const char *str = config_get("magic.power"); const char *str = config_get("magic.power");
double value = str ? atof(str) : 1.0; double value = str ? atof(str) : 1.0;
return MAX(value * force, 1.0f); return fmax(value * force, 1.0f);
} }
return 0; return 0;
} }
@ -141,6 +141,8 @@ static int a_readicastle(attrib * a, void *owner, struct gamedata *data)
storage *store = data->store; storage *store = data->store;
icastle_data *idata = (icastle_data *)a->data.v; icastle_data *idata = (icastle_data *)a->data.v;
char token[32]; char token[32];
(void)owner;
READ_TOK(store, token, sizeof(token)); READ_TOK(store, token, sizeof(token));
if (data->version < ATTRIBOWNER_VERSION) { if (data->version < ATTRIBOWNER_VERSION) {
READ_INT(store, NULL); READ_INT(store, NULL);
@ -154,7 +156,7 @@ static void
a_writeicastle(const attrib * a, const void *owner, struct storage *store) a_writeicastle(const attrib * a, const void *owner, struct storage *store)
{ {
icastle_data *data = (icastle_data *)a->data.v; icastle_data *data = (icastle_data *)a->data.v;
UNUSED_ARG(owner); (void)owner;
WRITE_TOK(store, data->type->_name); WRITE_TOK(store, data->type->_name);
WRITE_INT(store, data->time); WRITE_INT(store, data->time);
} }
@ -213,7 +215,7 @@ extern int dice(int count, int value);
/* ------------------------------------------------------------- */ /* ------------------------------------------------------------- */
/* aus dem alten System übriggebliegene Funktionen, die bei der /* aus dem alten System übriggebliegene Funktionen, die bei der
* Umwandlung von alt nach neu gebraucht werden */ * Umwandlung von alt nach neu gebraucht werden */
/* ------------------------------------------------------------- */ /* ------------------------------------------------------------- */
static void init_mage(attrib * a) static void init_mage(attrib * a)
{ {
@ -254,6 +256,7 @@ static int read_mage(attrib * a, void *owner, struct gamedata *data)
sc_mage *mage = (sc_mage *)a->data.v; sc_mage *mage = (sc_mage *)a->data.v;
char spname[64]; char spname[64];
(void)owner;
READ_INT(store, &mtype); READ_INT(store, &mtype);
mage->magietyp = (magic_t)mtype; mage->magietyp = (magic_t)mtype;
READ_INT(store, &mage->spellpoints); READ_INT(store, &mage->spellpoints);
@ -299,6 +302,7 @@ write_mage(const attrib * a, const void *owner, struct storage *store)
int i; int i;
sc_mage *mage = (sc_mage *)a->data.v; sc_mage *mage = (sc_mage *)a->data.v;
(void)owner;
WRITE_INT(store, mage->magietyp); WRITE_INT(store, mage->magietyp);
WRITE_INT(store, mage->spellpoints); WRITE_INT(store, mage->spellpoints);
WRITE_INT(store, mage->spchange); WRITE_INT(store, mage->spchange);
@ -360,6 +364,7 @@ static int read_seenspell(attrib * a, void *owner, struct gamedata *data)
spell *sp = 0; spell *sp = 0;
char token[32]; char token[32];
(void)owner;
READ_TOK(store, token, sizeof(token)); READ_TOK(store, token, sizeof(token));
if (data->version < UNIQUE_SPELLS_VERSION) { if (data->version < UNIQUE_SPELLS_VERSION) {
READ_INT(store, 0); /* ignore mtype */ READ_INT(store, 0); /* ignore mtype */
@ -377,6 +382,7 @@ static void
write_seenspell(const attrib * a, const void *owner, struct storage *store) write_seenspell(const attrib * a, const void *owner, struct storage *store)
{ {
const spell *sp = (const spell *)a->data.v; const spell *sp = (const spell *)a->data.v;
(void)owner;
WRITE_TOK(store, sp->sname); WRITE_TOK(store, sp->sname);
} }
@ -448,7 +454,7 @@ void pick_random_spells(faction * f, int level, spellbook * book, int num_spells
int maxspell = numspells; int maxspell = numspells;
int spellno = -1; int spellno = -1;
spellbook_entry *sbe = 0; spellbook_entry *sbe = 0;
while (!sbe && maxspell>0) { while (!sbe && maxspell > 0) {
spellno = rng_int() % maxspell; spellno = rng_int() % maxspell;
sbe = commonspells[spellno]; sbe = commonspells[spellno];
if (sbe->level > f->max_spelllevel) { if (sbe->level > f->max_spelllevel) {
@ -519,7 +525,10 @@ int get_combatspelllevel(const unit * u, int nr)
assert(nr < MAXCOMBATSPELLS); assert(nr < MAXCOMBATSPELLS);
if (m) { if (m) {
int level = effskill(u, SK_MAGIC, 0); int level = effskill(u, SK_MAGIC, 0);
return MIN(m->combatspells[nr].level, level); if (level < m->combatspells[nr].level) {
return level;
}
return m->combatspells[nr].level;
} }
return -1; return -1;
} }
@ -651,9 +660,13 @@ int change_spellpoints(unit * u, int mp)
} }
/* verhindere negative Magiepunkte */ /* verhindere negative Magiepunkte */
sp = MAX(m->spellpoints + mp, 0); sp = m->spellpoints + mp;
m->spellpoints = sp; if (sp > 0) {
m->spellpoints = sp;
}
else {
m->spellpoints = 0;
}
return sp; return sp;
} }
@ -678,10 +691,10 @@ static int get_spchange(const unit * u)
* entstehen * entstehen
*/ */
/* Artefakt der Stärke /* Artefakt der Stärke
* Ermöglicht dem Magier mehr Magiepunkte zu 'speichern' * Ermöglicht dem Magier mehr Magiepunkte zu 'speichern'
*/ */
/** TODO: at_skillmod daraus machen */ /** TODO: at_skillmod daraus machen */
static int use_item_aura(const region * r, const unit * u) static int use_item_aura(const region * r, const unit * u)
{ {
int sk, n; int sk, n;
@ -711,7 +724,7 @@ int max_spellpoints(const region * r, const unit * u)
if (n > 0) { if (n > 0) {
msp = (msp * n) / 100; msp = (msp * n) / 100;
} }
return MAX((int)msp, 0); return (msp > 0) ? (int)msp : 0;
} }
int change_maxspellpoints(unit * u, int csp) int change_maxspellpoints(unit * u, int csp)
@ -745,9 +758,7 @@ int countspells(unit * u, int step)
count = m->spellcount + step; count = m->spellcount + step;
/* negative Werte abfangen. */ m->spellcount = (count > 0) ? count : 0;
m->spellcount = MAX(0, count);
return m->spellcount; return m->spellcount;
} }
@ -827,7 +838,7 @@ int eff_spelllevel(unit * u, const spell * sp, int cast_level, int range)
} }
maxlevel = maxlevel =
get_pooled(u, sp->components[k].type, GET_DEFAULT, get_pooled(u, sp->components[k].type, GET_DEFAULT,
needplevel * cast_level) / needplevel; needplevel * cast_level) / needplevel;
/* sind die Kosten fix, so muss die Komponente nur einmal vorhanden /* sind die Kosten fix, so muss die Komponente nur einmal vorhanden
* sein und der cast_level ändert sich nicht */ * sein und der cast_level ändert sich nicht */
@ -839,7 +850,9 @@ int eff_spelllevel(unit * u, const spell * sp, int cast_level, int range)
} }
else if (sp->components[k].cost == SPC_LEVEL) { else if (sp->components[k].cost == SPC_LEVEL) {
costtyp = SPC_LEVEL; costtyp = SPC_LEVEL;
cast_level = MIN(cast_level, maxlevel); if (maxlevel < cast_level) {
cast_level = maxlevel;
}
/* bei Typ Linear müssen die Kosten in Höhe der Stufe vorhanden /* bei Typ Linear müssen die Kosten in Höhe der Stufe vorhanden
* sein, ansonsten schlägt der Spruch fehl */ * sein, ansonsten schlägt der Spruch fehl */
} }
@ -856,11 +869,13 @@ int eff_spelllevel(unit * u, const spell * sp, int cast_level, int range)
spellbook * sb = unit_get_spellbook(u); spellbook * sb = unit_get_spellbook(u);
if (sb) { if (sb) {
spellbook_entry * sbe = spellbook_get(sb, sp); spellbook_entry * sbe = spellbook_get(sb, sp);
if (sbe) { if (sbe && cast_level > sbe->level) {
return MIN(cast_level, sbe->level); return sbe->level;
} }
} }
log_error("spell %s is not in the spellbook for %s\n", sp->sname, unitname(u)); else {
log_error("spell %s is not in the spellbook for %s\n", sp->sname, unitname(u));
}
} }
return cast_level; return cast_level;
} }
@ -904,7 +919,7 @@ void pay_spell(unit * u, const spell * sp, int cast_level, int range)
*/ */
bool knowsspell(const region * r, const unit * u, const spell * sp) bool knowsspell(const region * r, const unit * u, const spell * sp)
{ {
/* Ist überhaupt ein gültiger Spruch angegeben? */ (void)r;
assert(sp); assert(sp);
/* steht der Spruch in der Spruchliste? */ /* steht der Spruch in der Spruchliste? */
return u_hasspell(u, sp) != 0; return u_hasspell(u, sp) != 0;
@ -1073,7 +1088,7 @@ spellpower(region * r, unit * u, const spell * sp, int cast_level, struct order
} }
} }
} }
return MAX(force, 0); return (force > 0) ? (int)force : 0;
} }
/* ------------------------------------------------------------- */ /* ------------------------------------------------------------- */
@ -1120,7 +1135,7 @@ variant magic_resistance(unit * target)
bool bad_resist = true; bool bad_resist = true;
if (rc == get_race(RC_HIRNTOETER) && !pl) { if (rc == get_race(RC_HIRNTOETER) && !pl) {
prob = frac_mul(prob, frac_make(1, 2)); prob = frac_mul(prob, frac_make(1, 2));
} }
assert(target->number > 0); assert(target->number > 0);
/* Magier haben einen Resistenzbonus vom Magietalent * 5% */ /* Magier haben einen Resistenzbonus vom Magietalent * 5% */
@ -1146,8 +1161,10 @@ variant magic_resistance(unit * target)
/* Auswirkungen von Zaubern auf der Region */ /* Auswirkungen von Zaubern auf der Region */
a = a_find(target->region->attribs, &at_curse); a = a_find(target->region->attribs, &at_curse);
while (a && a->type == &at_curse) { while (a && a->type == &at_curse) {
curse *c = (curse *)a->data.v; unit *mage;
unit *mage = c->magician;
c = (curse *)a->data.v;
mage = c->magician;
if (mage != NULL) { if (mage != NULL) {
if (good_resist && c->type == &ct_goodmagicresistancezone) { if (good_resist && c->type == &ct_goodmagicresistancezone) {
@ -1311,7 +1328,8 @@ bool fumble(region * r, unit * u, const spell * sp, int cast_grade)
int fumble_enabled = config_get_int("magic.fumble.enable", 1); int fumble_enabled = config_get_int("magic.fumble.enable", 1);
sc_mage * mage; sc_mage * mage;
if (effsk<=0 || !fumble_enabled) { (void)sp;
if (effsk <= 0 || !fumble_enabled) {
return false; return false;
} }
fumble_chance = (int)((cast_grade * 40.0 / (double)effsk) - 20.0); fumble_chance = (int)((cast_grade * 40.0 / (double)effsk) - 20.0);
@ -1366,7 +1384,7 @@ static void do_fumble(castorder * co)
int level = co->level; int level = co->level;
int duration; int duration;
double effect; double effect;
static const race *rc_toad; static const race *rc_toad;
static int rc_cache; static int rc_cache;
fumble_f fun; fumble_f fun;
@ -1413,7 +1431,8 @@ static void do_fumble(castorder * co)
case 2: case 2:
/* temporary skill loss */ /* temporary skill loss */
duration = MAX(rng_int() % level / 2, 2); duration = rng_int() % level / 2;
if (duration < 2) duration = 2;
effect = level / -2.0; effect = level / -2.0;
c = create_curse(u, &u->attribs, &ct_skillmod, level, c = create_curse(u, &u->attribs, &ct_skillmod, level,
duration, effect, 1); duration, effect, 1);
@ -1519,16 +1538,18 @@ void regenerate_aura(void)
* mindestens 1 Aura pro Monat */ * mindestens 1 Aura pro Monat */
regen = (int)reg_aura; regen = (int)reg_aura;
reg_aura -= regen; reg_aura -= regen;
if (chance(reg_aura)) if (chance(reg_aura)) {
++regen; ++regen;
regen = MAX(1, regen); }
regen = MIN((auramax - aura), regen); if (regen < 1) regen = 1;
if (regen > auramax - aura) regen = auramax - aura;
aura += regen; aura += regen;
ADDMSG(&u->faction->msgs, msg_message("regenaura", ADDMSG(&u->faction->msgs, msg_message("regenaura",
"unit region amount", u, r, regen)); "unit region amount", u, r, regen));
} }
set_spellpoints(u, MIN(aura, auramax)); if (aura > auramax) aura = auramax;
set_spellpoints(u, aura);
} }
} }
} }
@ -1536,7 +1557,7 @@ void regenerate_aura(void)
static bool static bool
verify_ship(region * r, unit * mage, const spell * sp, spllprm * spobj, verify_ship(region * r, unit * mage, const spell * sp, spllprm * spobj,
order * ord) order * ord)
{ {
ship *sh = findship(spobj->data.i); ship *sh = findship(spobj->data.i);
@ -1559,7 +1580,7 @@ order * ord)
static bool static bool
verify_building(region * r, unit * mage, const spell * sp, spllprm * spobj, verify_building(region * r, unit * mage, const spell * sp, spllprm * spobj,
order * ord) order * ord)
{ {
building *b = findbuilding(spobj->data.i); building *b = findbuilding(spobj->data.i);
@ -1602,7 +1623,7 @@ message *msg_unitnotfound(const struct unit * mage, struct order * ord,
static bool static bool
verify_unit(region * r, unit * mage, const spell * sp, spllprm * spobj, verify_unit(region * r, unit * mage, const spell * sp, spllprm * spobj,
order * ord) order * ord)
{ {
unit *u = NULL; unit *u = NULL;
switch (spobj->typ) { switch (spobj->typ) {
@ -1648,8 +1669,8 @@ order * ord)
* Sichtbarkeit. Dabei zählen wir die magieresistenten (resists) * Sichtbarkeit. Dabei zählen wir die magieresistenten (resists)
* Objekte. Alle anderen werten wir als Erfolge (success) */ * Objekte. Alle anderen werten wir als Erfolge (success) */
/* gibt bei Misserfolg 0 zurück, bei Magieresistenz zumindeste eines /* gibt bei Misserfolg 0 zurück, bei Magieresistenz zumindeste eines
* Objektes 1 und bei Erfolg auf ganzer Linie 2 */ * Objektes 1 und bei Erfolg auf ganzer Linie 2 */
static void static void
verify_targets(castorder * co, int *invalid, int *resist, int *success) verify_targets(castorder * co, int *invalid, int *resist, int *success)
{ {
@ -1845,7 +1866,7 @@ static int addparam_string(const char *const param[], spllprm ** spobjp)
spobj->flag = 0; spobj->flag = 0;
spobj->typ = SPP_STRING; spobj->typ = SPP_STRING;
spobj->data.xs = strdup(param[0]); spobj->data.xs = str_strdup(param[0]);
return 1; return 1;
} }
@ -1884,7 +1905,7 @@ static int addparam_building(const char *const param[], spllprm ** spobjp)
static int static int
addparam_region(const char *const param[], spllprm ** spobjp, const unit * u, addparam_region(const char *const param[], spllprm ** spobjp, const unit * u,
order * ord) order * ord)
{ {
assert(param[0]); assert(param[0]);
if (param[1] == 0) { if (param[1] == 0) {
@ -1920,7 +1941,7 @@ order * ord)
static int static int
addparam_unit(const char *const param[], spllprm ** spobjp, const unit * u, addparam_unit(const char *const param[], spllprm ** spobjp, const unit * u,
order * ord) order * ord)
{ {
spllprm *spobj; spllprm *spobj;
int i = 0; int i = 0;
@ -2156,6 +2177,7 @@ static void
a_write_unit(const attrib * a, const void *owner, struct storage *store) a_write_unit(const attrib * a, const void *owner, struct storage *store)
{ {
unit *u = (unit *)a->data.v; unit *u = (unit *)a->data.v;
(void)owner;
write_unit_reference(u, store); write_unit_reference(u, store);
} }
@ -2258,6 +2280,7 @@ void create_newfamiliar(unit * mage, unit * fam)
} }
static void * resolve_familiar(int id, void *data) { static void * resolve_familiar(int id, void *data) {
(void)id;
if (data) { if (data) {
unit *familiar = (unit *)data; unit *familiar = (unit *)data;
attrib *a = a_find(familiar->attribs, &at_familiarmage); attrib *a = a_find(familiar->attribs, &at_familiarmage);
@ -2271,6 +2294,7 @@ static void * resolve_familiar(int id, void *data) {
static int read_familiar(attrib * a, void *owner, struct gamedata *data) static int read_familiar(attrib * a, void *owner, struct gamedata *data)
{ {
(void)owner;
if (read_unit_reference(data, (unit **)&a->data.v, resolve_familiar) <= 0) { if (read_unit_reference(data, (unit **)&a->data.v, resolve_familiar) <= 0) {
return AT_READ_FAIL; return AT_READ_FAIL;
} }
@ -2303,7 +2327,7 @@ void create_newclone(unit * mage, unit * clone)
/* Wenn der Magier stirbt, wird das in destroy_unit abgefangen. /* Wenn der Magier stirbt, wird das in destroy_unit abgefangen.
* Kein Trigger, zu kompliziert. */ * Kein Trigger, zu kompliziert. */
/* Wenn der Klon stirbt, dann bekommt der Magier einen Schock */ /* Wenn der Klon stirbt, dann bekommt der Magier einen Schock */
add_trigger(&clone->attribs, "destroy", trigger_clonedied(mage)); add_trigger(&clone->attribs, "destroy", trigger_clonedied(mage));
} }
@ -2337,6 +2361,7 @@ unit *has_clone(unit * mage)
} }
static void * resolve_clone(int id, void *data) { static void * resolve_clone(int id, void *data) {
(void)id;
if (data) { if (data) {
unit *clone = (unit *)data; unit *clone = (unit *)data;
attrib *a = a_find(clone->attribs, &at_clonemage); attrib *a = a_find(clone->attribs, &at_clonemage);
@ -2350,6 +2375,7 @@ static void * resolve_clone(int id, void *data) {
static int read_clone(attrib * a, void *owner, struct gamedata *data) static int read_clone(attrib * a, void *owner, struct gamedata *data)
{ {
(void)owner;
if (read_unit_reference(data, (unit **)&a->data.v, resolve_clone) <= 0) { if (read_unit_reference(data, (unit **)&a->data.v, resolve_clone) <= 0) {
return AT_READ_FAIL; return AT_READ_FAIL;
} }
@ -2358,6 +2384,7 @@ static int read_clone(attrib * a, void *owner, struct gamedata *data)
/* mages */ /* mages */
static void * resolve_mage(int id, void *data) { static void * resolve_mage(int id, void *data) {
(void)id;
if (data) { if (data) {
unit *mage = (unit *)data; unit *mage = (unit *)data;
attrib *a = a_find(mage->attribs, &at_familiar); attrib *a = a_find(mage->attribs, &at_familiar);
@ -2371,6 +2398,7 @@ static void * resolve_mage(int id, void *data) {
static int read_magician(attrib * a, void *owner, struct gamedata *data) static int read_magician(attrib * a, void *owner, struct gamedata *data)
{ {
(void)owner;
if (read_unit_reference(data, (unit **)&a->data.v, resolve_mage) <= 0) { if (read_unit_reference(data, (unit **)&a->data.v, resolve_mage) <= 0) {
return AT_READ_FAIL; return AT_READ_FAIL;
} }
@ -2381,7 +2409,7 @@ static int age_unit(attrib * a, void *owner)
/* if unit is gone or dead, remove the attribute */ /* if unit is gone or dead, remove the attribute */
{ {
unit *u = (unit *)a->data.v; unit *u = (unit *)a->data.v;
UNUSED_ARG(owner); (void)owner;
return (u != NULL && u->number > 0) ? AT_AGE_KEEP : AT_AGE_REMOVE; return (u != NULL && u->number > 0) ? AT_AGE_KEEP : AT_AGE_REMOVE;
} }
@ -2433,9 +2461,9 @@ unit *get_familiar(const unit * u)
{ {
attrib *a = a_find(u->attribs, &at_familiar); attrib *a = a_find(u->attribs, &at_familiar);
if (a != NULL) { if (a != NULL) {
unit *u = (unit *)a->data.v; unit *uf = (unit *)a->data.v;
if (u->number > 0) if (uf->number > 0)
return u; return uf;
} }
return NULL; return NULL;
} }
@ -2444,9 +2472,9 @@ unit *get_familiar_mage(const unit * u)
{ {
attrib *a = a_find(u->attribs, &at_familiarmage); attrib *a = a_find(u->attribs, &at_familiarmage);
if (a != NULL) { if (a != NULL) {
unit *u = (unit *)a->data.v; unit *um = (unit *)a->data.v;
if (u->number > 0) if (um->number > 0)
return u; return um;
} }
return NULL; return NULL;
} }
@ -2455,9 +2483,9 @@ unit *get_clone(const unit * u)
{ {
attrib *a = a_find(u->attribs, &at_clone); attrib *a = a_find(u->attribs, &at_clone);
if (a != NULL) { if (a != NULL) {
unit *u = (unit *)a->data.v; unit *uc = (unit *)a->data.v;
if (u->number > 0) if (uc->number > 0)
return u; return uc;
} }
return NULL; return NULL;
} }
@ -2466,14 +2494,14 @@ unit *get_clone_mage(const unit * u)
{ {
attrib *a = a_find(u->attribs, &at_clonemage); attrib *a = a_find(u->attribs, &at_clonemage);
if (a != NULL) { if (a != NULL) {
unit *u = (unit *)a->data.v; unit *um = (unit *)a->data.v;
if (u->number > 0) if (um->number > 0)
return u; return um;
} }
return NULL; return NULL;
} }
static bool is_moving_ship(const region * r, ship * sh) static bool is_moving_ship(ship * sh)
{ {
const unit *u = ship_owner(sh); const unit *u = ship_owner(sh);
@ -2485,7 +2513,7 @@ static bool is_moving_ship(const region * r, ship * sh)
return true; return true;
default: default:
return false; return false;
} }
return false; return false;
} }
@ -2507,7 +2535,7 @@ static castorder *cast_cmd(unit * u, order * ord)
cmistake(u, ord, 224, MSG_MAGIC); cmistake(u, ord, 224, MSG_MAGIC);
return 0; return 0;
} }
pl = rplane(r); pl = getplane(r);
if (pl && fval(pl, PFL_NOMAGIC)) { if (pl && fval(pl, PFL_NOMAGIC)) {
cmistake(u, ord, 269, MSG_MAGIC); cmistake(u, ord, 269, MSG_MAGIC);
return 0; return 0;
@ -2520,7 +2548,7 @@ static castorder *cast_cmd(unit * u, order * ord)
/* für Syntax ' STUFE x REGION y z ' */ /* für Syntax ' STUFE x REGION y z ' */
if (param == P_LEVEL) { if (param == P_LEVEL) {
int p = getint(); int p = getint();
level = MIN(p, level); if (level > p) level = p;
if (level < 1) { if (level < 1) {
/* Fehler "Das macht wenig Sinn" */ /* Fehler "Das macht wenig Sinn" */
syntax_error(u, ord); syntax_error(u, ord);
@ -2532,7 +2560,7 @@ static castorder *cast_cmd(unit * u, order * ord)
if (param == P_REGION) { if (param == P_REGION) {
int t_x = getint(); int t_x = getint();
int t_y = getint(); int t_y = getint();
plane *pl = getplane(u->region);
t_x = rel_to_abs(pl, u->faction, t_x, 0); t_x = rel_to_abs(pl, u->faction, t_x, 0);
t_y = rel_to_abs(pl, u->faction, t_y, 1); t_y = rel_to_abs(pl, u->faction, t_y, 1);
pnormalize(&t_x, &t_y, pl); pnormalize(&t_x, &t_y, pl);
@ -2550,7 +2578,7 @@ static castorder *cast_cmd(unit * u, order * ord)
* hier nach REGION nochmal auf STUFE prüfen */ * hier nach REGION nochmal auf STUFE prüfen */
if (param == P_LEVEL) { if (param == P_LEVEL) {
int p = getint(); int p = getint();
level = MIN(p, level); if (level > p) level = p;
if (level < 1) { if (level < 1) {
/* Fehler "Das macht wenig Sinn" */ /* Fehler "Das macht wenig Sinn" */
syntax_error(u, ord); syntax_error(u, ord);
@ -2619,7 +2647,7 @@ static castorder *cast_cmd(unit * u, order * ord)
* ONSHIPCAST deklarierte Zauber sprechen */ * ONSHIPCAST deklarierte Zauber sprechen */
} }
else if (u->ship) { else if (u->ship) {
if (is_moving_ship(r, u->ship)) { if (is_moving_ship(u->ship)) {
if (!(sp->sptyp & ONSHIPCAST)) { if (!(sp->sptyp & ONSHIPCAST)) {
/* Fehler: "Diesen Spruch kann man nicht auf einem sich /* Fehler: "Diesen Spruch kann man nicht auf einem sich
* bewegenden Schiff stehend zaubern" */ * bewegenden Schiff stehend zaubern" */
@ -2666,12 +2694,14 @@ static castorder *cast_cmd(unit * u, order * ord)
return 0; return 0;
} }
if (caster != familiar) { /* Magier zaubert durch Vertrauten */ if (caster != familiar) { /* Magier zaubert durch Vertrauten */
int sk;
if (range > 1) { /* Fehler! Versucht zu Farcasten */ if (range > 1) { /* Fehler! Versucht zu Farcasten */
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "familiar_farcast", ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "familiar_farcast",
"mage", caster)); "mage", caster));
return 0; return 0;
} }
if (distance(caster->region, r) > effskill(caster, SK_MAGIC, 0)) { sk = effskill(caster, SK_MAGIC, 0);
if (distance(caster->region, r) > sk) {
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "familiar_toofar", ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "familiar_toofar",
"mage", caster)); "mage", caster));
return 0; return 0;
@ -2681,7 +2711,8 @@ static castorder *cast_cmd(unit * u, order * ord)
* löschen, zaubern kann er noch */ * löschen, zaubern kann er noch */
range *= 2; range *= 2;
set_order(&caster->thisorder, NULL); set_order(&caster->thisorder, NULL);
level = MIN(level, effskill(caster, SK_MAGIC, 0) / 2); sk /= 2;
if (level > sk) level = sk;
} }
} }
/* Weitere Argumente zusammenbasteln */ /* Weitere Argumente zusammenbasteln */
@ -2704,7 +2735,7 @@ static castorder *cast_cmd(unit * u, order * ord)
break; break;
} }
} }
params[p++] = strdup(s); params[p++] = str_strdup(s);
} }
params[p] = 0; params[p] = 0;
args = args =
@ -2744,7 +2775,6 @@ void magic(void)
{ {
region *r; region *r;
int rank; int rank;
castorder *co;
spellrank spellranks[MAX_SPELLRANK]; spellrank spellranks[MAX_SPELLRANK];
const race *rc_insect = get_race(RC_INSECT); const race *rc_insect = get_race(RC_INSECT);
@ -2787,6 +2817,7 @@ void magic(void)
* Spruch gezaubert wird) */ * Spruch gezaubert wird) */
for (rank = 0; rank < MAX_SPELLRANK; rank++) { for (rank = 0; rank < MAX_SPELLRANK; rank++) {
castorder *co;
for (co = spellranks[rank].begin; co; co = co->next) { for (co = spellranks[rank].begin; co; co = co->next) {
order *ord = co->order; order *ord = co->order;
int invalid, resist, success, cast_level = co->level; int invalid, resist, success, cast_level = co->level;
@ -3000,7 +3031,7 @@ spellbook * get_spellbook(const char * name)
const void * match; const void * match;
if (len >= SBNAMELEN) { if (len >= SBNAMELEN) {
log_error("spellbook name is longer than %d bytes: %s", SBNAMELEN-1, name); log_error("spellbook name is longer than %d bytes: %s", SBNAMELEN - 1, name);
return NULL; return NULL;
} }
@ -3026,6 +3057,9 @@ void free_spellbook(spellbook *sb) {
static int free_spellbook_cb(const void *match, const void *key, size_t keylen, void *data) { static int free_spellbook_cb(const void *match, const void *key, size_t keylen, void *data) {
const sb_entry *ent = (const sb_entry *)match; const sb_entry *ent = (const sb_entry *)match;
(void)data;
(void)keylen;
(void)key;
free_spellbook(ent->value); free_spellbook(ent->value);
return 0; return 0;
} }

View file

@ -18,6 +18,7 @@
#include <util/attrib.h> #include <util/attrib.h>
#include <util/language.h> #include <util/language.h>
#include <util/strings.h>
#include <CuTest.h> #include <CuTest.h>
#include <selist.h> #include <selist.h>
@ -476,7 +477,7 @@ static void test_illusioncastle(CuTest *tc)
CuAssertPtrEquals(tc, btype, (void *)icastle_type(a)); CuAssertPtrEquals(tc, btype, (void *)icastle_type(a));
CuAssertPtrEquals(tc, bt_icastle, (void *)b->type); CuAssertPtrEquals(tc, bt_icastle, (void *)b->type);
CuAssertStrEquals(tc, "castle", buildingtype(btype, b, b->size)); CuAssertStrEquals(tc, "castle", buildingtype(btype, b, b->size));
btype->construction->name = strdup("site"); btype->construction->name = str_strdup("site");
CuAssertStrEquals(tc, "site", buildingtype(btype, b, b->size)); CuAssertStrEquals(tc, "site", buildingtype(btype, b, b->size));
test_teardown(); test_teardown();
} }

View file

@ -39,6 +39,7 @@
#include <util/log.h> #include <util/log.h>
#include <selist.h> #include <selist.h>
#include <util/rng.h> #include <util/rng.h>
#include <util/strings.h>
#include <util/unicode.h> #include <util/unicode.h>
/* libc includes */ /* libc includes */
@ -186,13 +187,13 @@ newfaction *read_newfactions(const char *filename)
} }
nf = calloc(sizeof(newfaction), 1); nf = calloc(sizeof(newfaction), 1);
if (check_email(email) == 0) { if (check_email(email) == 0) {
nf->email = strdup(email); nf->email = str_strdup(email);
} else { } else {
log_error("Invalid email address for subscription %s: %s\n", itoa36(subscription), email); log_error("Invalid email address for subscription %s: %s\n", itoa36(subscription), email);
free(nf); free(nf);
continue; continue;
} }
nf->password = strdup(password); nf->password = str_strdup(password);
nf->race = rc_find(race); nf->race = rc_find(race);
nf->subscription = subscription; nf->subscription = subscription;
if (alliances != NULL) { if (alliances != NULL) {

View file

@ -1,5 +1,3 @@
#include <platform.h>
#include <kernel/config.h>
#include "piracy.h" #include "piracy.h"
#include "direction.h" #include "direction.h"
@ -68,8 +66,9 @@ static attrib *mk_piracy(const faction * pirate, const faction * target,
static bool validate_pirate(unit *u, order *ord) { static bool validate_pirate(unit *u, order *ord) {
assert(u); assert(u);
assert(ord); assert(ord);
if (fval(u_race(u), RCF_SWIM | RCF_FLY)) if (u_race(u)->flags & (RCF_SWIM | RCF_FLY)) {
return true; return true;
}
if (!u->ship) { if (!u->ship) {
cmistake(u, ord, 144, MSG_MOVE); cmistake(u, ord, 144, MSG_MOVE);
return false; return false;
@ -155,8 +154,8 @@ void piracy_cmd(unit * u)
/* TODO this could still result in an illegal movement order (through a wall or whatever) /* TODO this could still result in an illegal movement order (through a wall or whatever)
* which will be prevented by move_cmd below */ * which will be prevented by move_cmd below */
if (rc && if (rc &&
((sh && !fval(rc->terrain, FORBIDDEN_REGION) && can_takeoff(sh, r, rc)) ((sh && !(rc->terrain->flags & FORBIDDEN_REGION) && can_takeoff(sh, r, rc))
|| (canswim(u) && fval(rc->terrain, SWIM_INTO) && fval(rc->terrain, SEA_REGION)))) { || (canswim(u) && ((rc->terrain->flags & (SWIM_INTO|SEA_REGION)) == (SWIM_INTO | SEA_REGION))))) {
for (sh2 = rc->ships; sh2; sh2 = sh2->next) { for (sh2 = rc->ships; sh2; sh2 = sh2->next) {
unit *cap = ship_owner(sh2); unit *cap = ship_owner(sh2);

View file

@ -4,17 +4,11 @@
#define _LP64 0 /* fix a warning in pdcurses 3.4 */ #define _LP64 0 /* fix a warning in pdcurses 3.4 */
#endif #endif
#ifndef UNILIB_H
#define UNILIB_H
#ifdef _MSC_VER #ifdef _MSC_VER
#ifndef __STDC__ #ifndef __STDC__
#define __STDC__ 1 // equivalent to /Za #define __STDC__ 1 // equivalent to /Za
#endif #endif
#define NO_STRDUP
#define NO_MKDIR #define NO_MKDIR
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#if _MSC_VER >= 1900 #if _MSC_VER >= 1900
#pragma warning(disable: 4710 4820) #pragma warning(disable: 4710 4820)
#pragma warning(disable: 4100) // unreferenced formal parameter #pragma warning(disable: 4100) // unreferenced formal parameter
@ -42,10 +36,6 @@
#define TOLUA_CAST (char*) #define TOLUA_CAST (char*)
#ifdef NO_STRDUP
char * strdup(const char *s);
#endif
#ifdef NO_MKDIR #ifdef NO_MKDIR
int mkdir(const char *pathname, int mode); int mkdir(const char *pathname, int mode);
#endif #endif
@ -54,6 +44,3 @@ int mkdir(const char *pathname, int mode);
#define PI_F 3.1415926535897932384626433832795F #define PI_F 3.1415926535897932384626433832795F
#define PI_D 3.1415926535897932384626433832795 #define PI_D 3.1415926535897932384626433832795
#define PI_L 3.1415926535897932384626433832795L #define PI_L 3.1415926535897932384626433832795L
#endif

View file

@ -2,6 +2,7 @@
#include "prefix.h" #include "prefix.h"
#include <util/log.h> #include <util/log.h>
#include <util/strings.h>
#include <assert.h> #include <assert.h>
#include <stddef.h> #include <stddef.h>
@ -30,7 +31,7 @@ int add_raceprefix(const char *prefix)
race_prefixes = tmp; race_prefixes = tmp;
size *= 2; size *= 2;
} }
race_prefixes[next++] = strdup(prefix); race_prefixes[next++] = str_strdup(prefix);
race_prefixes[next] = NULL; race_prefixes[next] = NULL;
return 0; return 0;
} }

View file

@ -85,8 +85,10 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <util/log.h> #include <util/log.h>
#include <util/message.h> #include <util/message.h>
#include <util/nrmessage.h> #include <util/nrmessage.h>
#include <selist.h>
#include <util/rng.h> #include <util/rng.h>
#include <util/strings.h>
#include <selist.h>
#include <filestream.h> #include <filestream.h>
#include <stream.h> #include <stream.h>
@ -936,7 +938,7 @@ void report_region(struct stream *out, const region * r, faction * f)
} }
if (!e) { if (!e) {
e = calloc(sizeof(struct edge), 1); e = calloc(sizeof(struct edge), 1);
e->name = strdup(name); e->name = str_strdup(name);
e->transparent = transparent; e->transparent = transparent;
e->next = edges; e->next = edges;
edges = e; edges = e;

View file

@ -18,6 +18,7 @@
#include <util/language.h> #include <util/language.h>
#include <util/lists.h> #include <util/lists.h>
#include <util/message.h> #include <util/message.h>
#include <util/strings.h>
#include <stream.h> #include <stream.h>
#include <memstream.h> #include <memstream.h>
@ -223,7 +224,7 @@ static void cleanup_spell_fixture(spell_fixture *spf) {
static void set_parameter(spell_fixture spell, char *value) { static void set_parameter(spell_fixture spell, char *value) {
free(spell.sp->parameter); free(spell.sp->parameter);
spell.sp->parameter = strdup(value); spell.sp->parameter = str_strdup(value);
} }
static void check_spell_syntax(CuTest *tc, char *msg, spell_fixture *spell, char *syntax) { static void check_spell_syntax(CuTest *tc, char *msg, spell_fixture *spell, char *syntax) {
@ -294,14 +295,14 @@ static void test_write_spell_syntax(CuTest *tc) {
set_parameter(spell, "bc"); set_parameter(spell, "bc");
free(spell.sp->syntax); free(spell.sp->syntax);
spell.sp->syntax = strdup("hodor"); spell.sp->syntax = str_strdup("hodor");
check_spell_syntax(tc, "bc hodor", &spell, " ZAUBERE \"Testzauber\" <bnr> <Hodor>"); check_spell_syntax(tc, "bc hodor", &spell, " ZAUBERE \"Testzauber\" <bnr> <Hodor>");
free(spell.sp->syntax); free(spell.sp->syntax);
spell.sp->syntax = 0; spell.sp->syntax = 0;
set_parameter(spell, "c?"); set_parameter(spell, "c?");
free(spell.sp->syntax); free(spell.sp->syntax);
spell.sp->syntax = strdup("hodor"); spell.sp->syntax = str_strdup("hodor");
check_spell_syntax(tc, "c?", &spell, " ZAUBERE \"Testzauber\" [<Hodor>]"); check_spell_syntax(tc, "c?", &spell, " ZAUBERE \"Testzauber\" [<Hodor>]");
free(spell.sp->syntax); free(spell.sp->syntax);
spell.sp->syntax = 0; spell.sp->syntax = 0;

View file

@ -60,14 +60,15 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
/* util includes */ /* util includes */
#include <util/attrib.h> #include <util/attrib.h>
#include <util/bsdstring.h>
#include <util/base36.h> #include <util/base36.h>
#include <util/bsdstring.h>
#include <util/functions.h> #include <util/functions.h>
#include <util/translation.h>
#include <util/goodies.h> #include <util/goodies.h>
#include <util/language.h> #include <util/language.h>
#include <util/lists.h> #include <util/lists.h>
#include <util/log.h> #include <util/log.h>
#include <util/strings.h>
#include <util/translation.h>
#include <stream.h> #include <stream.h>
#include <selist.h> #include <selist.h>
@ -1667,7 +1668,7 @@ int reports(void)
static variant var_copy_string(variant x) static variant var_copy_string(variant x)
{ {
x.v = x.v ? strdup((const char *)x.v) : 0; x.v = x.v ? str_strdup((const char *)x.v) : 0;
return x; return x;
} }

View file

@ -6,6 +6,7 @@
#include <util/log.h> #include <util/log.h>
#include <util/base36.h> #include <util/base36.h>
#include <util/log.h> #include <util/log.h>
#include <util/strings.h>
#include <selist.h> #include <selist.h>
#include <sqlite3.h> #include <sqlite3.h>
#include <assert.h> #include <assert.h>
@ -41,9 +42,9 @@ read_factions(sqlite3 * db, int game_id) {
text = (const char *)sqlite3_column_text(stmt, 1); text = (const char *)sqlite3_column_text(stmt, 1);
if (text) dbf->no = atoi36(text); if (text) dbf->no = atoi36(text);
text = (const char *)sqlite3_column_text(stmt, 2); text = (const char *)sqlite3_column_text(stmt, 2);
if (text) dbf->name = strdup(text); if (text) dbf->name = str_strdup(text);
text = (const char *)sqlite3_column_text(stmt, 3); text = (const char *)sqlite3_column_text(stmt, 3);
if (text) dbf->email = strdup(text); if (text) dbf->email = str_strdup(text);
selist_push(&result, dbf); selist_push(&result, dbf);
res = sqlite3_step(stmt); res = sqlite3_step(stmt);
} }

View file

@ -7,6 +7,7 @@
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include <util/log.h> #include <util/log.h>
#include <util/strings.h>
#include <util/variant.h> #include <util/variant.h>
#pragma warning(disable: 4210) #pragma warning(disable: 4210)
@ -35,7 +36,7 @@ static void add_suite(CuSuite *(*csuite)(void), const char *name, int argc, char
} }
if (s) { if (s) {
s->next = suites; s->next = suites;
s->name = strdup(name); s->name = str_strdup(name);
s->csuite = csuite(); s->csuite = csuite();
suites = s; suites = s;
} }

View file

@ -19,10 +19,11 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <platform.h> #include <platform.h>
#include "attrib.h" #include "attrib.h"
#include "gamedata.h"
#include "log.h" #include "log.h"
#include "storage.h" #include "storage.h"
#include "strings.h"
#include <util/gamedata.h>
#include <critbit.h> #include <critbit.h>
#include <assert.h> #include <assert.h>
@ -129,7 +130,7 @@ int a_readstring(attrib * a, void *owner, struct gamedata *data)
len += DISPLAYSIZE - 1; len += DISPLAYSIZE - 1;
} }
else { else {
result = strdup(buf); result = str_strdup(buf);
} }
} while (e == ENOMEM); } while (e == ENOMEM);
a->data.v = result; a->data.v = result;

View file

@ -2,6 +2,7 @@
#include "attrib.h" #include "attrib.h"
#include <util/gamedata.h> #include <util/gamedata.h>
#include <util/strings.h>
#include <storage.h> #include <storage.h>
#include <memstream.h> #include <memstream.h>
@ -119,7 +120,7 @@ static void test_attrib_rwstring(CuTest *tc) {
attrib a = { 0 }; attrib a = { 0 };
test_setup(); test_setup();
a.data.v = strdup("Hello World"); a.data.v = str_strdup("Hello World");
mstream_init(&data.strm); mstream_init(&data.strm);
gamedata_init(&data, &store, RELEASE_VERSION); gamedata_init(&data, &store, RELEASE_VERSION);
a_writestring(&a, NULL, &store); a_writestring(&a, NULL, &store);

View file

@ -23,7 +23,9 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include "attrib.h" #include "attrib.h"
#include "gamedata.h" #include "gamedata.h"
#include "log.h" #include "log.h"
#include "storage.h" #include "strings.h"
#include <storage.h>
/* libc includes */ /* libc includes */
#include <assert.h> #include <assert.h>
@ -153,7 +155,7 @@ static int read_handler(attrib * a, void *owner, gamedata *data)
handler_info *hi = (handler_info *)a->data.v; handler_info *hi = (handler_info *)a->data.v;
READ_TOK(store, zText, sizeof(zText)); READ_TOK(store, zText, sizeof(zText));
hi->event = strdup(zText); hi->event = str_strdup(zText);
read_triggers(data, &hi->triggers); read_triggers(data, &hi->triggers);
if (hi->triggers != NULL) { if (hi->triggers != NULL) {
return AT_READ_OK; return AT_READ_OK;
@ -200,7 +202,7 @@ void add_trigger(struct attrib **ap, const char *eventname, struct trigger *t)
if (a == NULL || a->type != &at_eventhandler) { if (a == NULL || a->type != &at_eventhandler) {
a = a_add(ap, a_new(&at_eventhandler)); a = a_add(ap, a_new(&at_eventhandler));
td = (handler_info *)a->data.v; td = (handler_info *)a->data.v;
td->event = strdup(eventname); td->event = str_strdup(eventname);
} }
tp = &td->triggers; tp = &td->triggers;
while (*tp) while (*tp)

View file

@ -16,7 +16,6 @@ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
**/ **/
#include <platform.h>
#include "language.h" #include "language.h"
#include "log.h" #include "log.h"
@ -83,7 +82,7 @@ locale *get_or_create_locale(const char *name)
*lp = l = (locale *)calloc(sizeof(locale), 1); *lp = l = (locale *)calloc(sizeof(locale), 1);
assert_alloc(l); assert_alloc(l);
l->hashkey = hkey; l->hashkey = hkey;
l->name = strdup(name); l->name = str_strdup(name);
l->index = nextlocaleindex++; l->index = nextlocaleindex++;
assert(nextlocaleindex <= MAXLOCALES); assert(nextlocaleindex <= MAXLOCALES);
if (default_locale == NULL) default_locale = l; if (default_locale == NULL) default_locale = l;
@ -206,15 +205,15 @@ void locale_setstring(locale * lang, const char *key, const char *value)
find->nexthash = lang->strings[id]; find->nexthash = lang->strings[id];
lang->strings[id] = find; lang->strings[id] = find;
find->hashkey = hkey; find->hashkey = hkey;
find->key = strdup(key); find->key = str_strdup(key);
find->str = strdup(value); find->str = str_strdup(value);
} }
else { else {
if (strcmp(find->str, value) != 0) { if (strcmp(find->str, value) != 0) {
log_warning("multiple translations for key %s\n", key); log_warning("multiple translations for key %s\n", key);
} }
free(find->str); free(find->str);
find->str = strdup(value); find->str = str_strdup(value);
} }
} }

View file

@ -16,9 +16,10 @@ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
**/ **/
#include <platform.h>
#include "lists.h" #include "lists.h"
#include "strings.h"
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <assert.h> #include <assert.h>
@ -117,7 +118,7 @@ void addstrlist(strlist ** SP, const char *s)
{ {
strlist *slist = malloc(sizeof(strlist)); strlist *slist = malloc(sizeof(strlist));
slist->next = NULL; slist->next = NULL;
slist->s = strdup(s); slist->s = str_strdup(s);
addlist(SP, slist); addlist(SP, slist);
} }

View file

@ -74,7 +74,7 @@ message_type *mt_new(const char *name, const char *args[])
} }
mtype = (message_type *)malloc(sizeof(message_type)); mtype = (message_type *)malloc(sizeof(message_type));
mtype->key = 0; mtype->key = 0;
mtype->name = strdup(name); mtype->name = str_strdup(name);
mtype->nparameters = nparameters; mtype->nparameters = nparameters;
if (nparameters > 0) { if (nparameters > 0) {
mtype->pnames = (char **)malloc(sizeof(char *) * nparameters); mtype->pnames = (char **)malloc(sizeof(char *) * nparameters);

View file

@ -91,7 +91,7 @@ const nrsection *section_add(const char *name)
} }
if (!*mcp) { if (!*mcp) {
nrsection *mc = calloc(sizeof(nrsection), 1); nrsection *mc = calloc(sizeof(nrsection), 1);
mc->name = strdup(name); mc->name = str_strdup(name);
*mcp = mc; *mcp = mc;
} }
return *mcp; return *mcp;
@ -130,14 +130,14 @@ const char *string, int level, const char *section)
nrt->section = NULL; nrt->section = NULL;
nrtypes[hash] = nrt; nrtypes[hash] = nrt;
assert(string && *string); assert(string && *string);
nrt->string = strdup(string); nrt->string = str_strdup(string);
*c = '\0'; *c = '\0';
for (i = 0; i != mtype->nparameters; ++i) { for (i = 0; i != mtype->nparameters; ++i) {
if (i != 0) if (i != 0)
*c++ = ' '; *c++ = ' ';
c += strlcpy(c, mtype->pnames[i], sizeof(zNames)-(c-zNames)); c += strlcpy(c, mtype->pnames[i], sizeof(zNames)-(c-zNames));
} }
nrt->vars = strdup(zNames); nrt->vars = str_strdup(zNames);
} }
} }

View file

@ -16,8 +16,6 @@ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
**/ **/
#include <platform.h>
#include "strings.h" #include "strings.h"
#include "assert.h" #include "assert.h"
@ -168,3 +166,11 @@ unsigned int wang_hash(unsigned int a)
a = a ^ (a >> 16); a = a ^ (a >> 16);
return a; return a;
} }
char *str_strdup(const char *s) {
#ifdef _MSC_VER
return _strdup(s);
#else
return strdup(s);
#endif
}

View file

@ -30,6 +30,7 @@ extern "C" {
char *set_string(char **s, const char *neu); char *set_string(char **s, const char *neu);
unsigned int str_hash(const char *s); unsigned int str_hash(const char *s);
size_t str_slprintf(char * dst, size_t size, const char * format, ...); size_t str_slprintf(char * dst, size_t size, const char * format, ...);
char *str_strdup(const char *s);
unsigned int jenkins_hash(unsigned int a); unsigned int jenkins_hash(unsigned int a);
unsigned int wang_hash(unsigned int a); unsigned int wang_hash(unsigned int a);

View file

@ -8,6 +8,7 @@
#include <util/gamedata.h> #include <util/gamedata.h>
#include <util/language.h> #include <util/language.h>
#include <util/log.h> #include <util/log.h>
#include <util/strings.h>
#include <util/umlaut.h> #include <util/umlaut.h>
#include <util/variant.h> #include <util/variant.h>
@ -43,7 +44,7 @@ void register_special_direction(struct locale *lang, const char *name)
if (token) { if (token) {
void **tokens = get_translations(lang, UT_SPECDIR); void **tokens = get_translations(lang, UT_SPECDIR);
variant var; variant var;
char *str = strdup(name); char *str = str_strdup(name);
var.v = str; var.v = str;
addtoken((struct tnode **)tokens, token, var); addtoken((struct tnode **)tokens, token, var);
@ -96,9 +97,9 @@ static int a_readdirection(attrib * a, void *owner, struct gamedata *data)
READ_INT(store, &d->y); READ_INT(store, &d->y);
READ_INT(store, &d->duration); READ_INT(store, &d->duration);
READ_TOK(store, lbuf, sizeof(lbuf)); READ_TOK(store, lbuf, sizeof(lbuf));
d->desc = strdup(lbuf); d->desc = str_strdup(lbuf);
READ_TOK(store, lbuf, sizeof(lbuf)); READ_TOK(store, lbuf, sizeof(lbuf));
d->keyword = strdup(lbuf); d->keyword = str_strdup(lbuf);
d->active = true; d->active = true;
return AT_READ_OK; return AT_READ_OK;
} }
@ -153,8 +154,8 @@ attrib *create_special_direction(region * r, region * rt, int duration,
d->x = rt->x; d->x = rt->x;
d->y = rt->y; d->y = rt->y;
d->duration = duration; d->duration = duration;
d->desc = strdup(desc); d->desc = str_strdup(desc);
d->keyword = strdup(keyword); d->keyword = str_strdup(keyword);
return a; return a;
} }