From f8398db851e61b60589c93267493ec6410e32f40 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Thu, 11 Oct 2007 21:48:31 +0000 Subject: [PATCH] - compiling in VS2005 on my new PC - eliminating a couple of warnings - fixed a crash bug or two in the -x option - fixed an endless loop in give_item --- src/common/gamecode/creation.h | 17 +----------- src/common/gamecode/economy.c | 18 ++++++++----- src/common/kernel/battle.c | 2 +- src/common/kernel/border.c | 49 +++++++++++++++++----------------- src/common/kernel/save.c | 12 ++++++++- src/common/util/attrib.c | 2 +- src/config.h | 11 ++++++-- src/eressea/lua/message.cpp | 3 +++ 8 files changed, 62 insertions(+), 52 deletions(-) diff --git a/src/common/gamecode/creation.h b/src/common/gamecode/creation.h index 2add7afd9..eb265c4bf 100644 --- a/src/common/gamecode/creation.h +++ b/src/common/gamecode/creation.h @@ -1,7 +1,7 @@ /* vi: set ts=2: * * - * Eressea PB(E)M host Copyright (C) 1998-2003 + * Eressea PB(E)M host Copyright (C) 1998-2007 * Christian Schlittchen (corwin@amber.kn-bremen.de) * Katja Zedel (katze@felidae.kn-bremen.de) * Henning Peters (faroul@beyond.kn-bremen.de) @@ -17,22 +17,7 @@ extern "C" { #endif -/* entweder eine grosse Insel (Chance 2/3) mit 25 bis 34 Felder oder eine - * kleine Insel (Chance 1/3) mit 11 bis 24 Feldern. */ - -enum { - M_TERRAIN, - M_FACTIONS, - M_UNARMED, - MAXMODES -}; - void createmonsters(void); -void addunit(void); -void makeblock(int x1, int y1, char chaos); -void writemap(FILE * F, int mode); - -void regionspells(void); #ifdef __cplusplus } diff --git a/src/common/gamecode/economy.c b/src/common/gamecode/economy.c index e07e3a254..bfdd4826d 100644 --- a/src/common/gamecode/economy.c +++ b/src/common/gamecode/economy.c @@ -679,16 +679,18 @@ give_cmd(unit * u, order * ord) if (u->items) { item **itmp=&u->items; while (*itmp) { - const item_type * itype = (*itmp)->type; - if (fval(itype, ITF_HERB) && (*itmp)->number>0) { + item * itm = *itmp; + const item_type * itype = itm->type; + if (fval(itype, ITF_HERB) && itm->number>0) { /* give_item ändert im fall,das man alles übergibt, die * item-liste der unit, darum continue vor pointerumsetzten */ - if (give_item((*itmp)->number, (*itmp)->type, u, u2, ord)==0) { + if (give_item(itm->number, itm->type, u, u2, ord)==0) { given = true; + if (*itmp!=itm) continue; continue; } } - itmp = &(*itmp)->next; + itmp = &itm->next; } } if (!given) cmistake(u, ord, 38, MSG_COMMERCE); @@ -746,7 +748,9 @@ give_cmd(unit * u, order * ord) const item_type * itype = itm->type; if (itm->number > 0 && itm->number - get_reservation(u, itype->rtype) > 0) { n = itm->number - get_reservation(u, itype->rtype); - if (give_item(n, itype, u, u2, ord)==0) continue; + if (give_item(n, itype, u, u2, ord)==0) { + if (*itmp!=itm) continue; + } } itmp = &itm->next; } @@ -1221,11 +1225,11 @@ economics(region *r) /* RECRUIT orders */ for (u = r->units; u; u = u->next) { - order * ord; + order * ord; if (!recruit_classic()) { if (u->number>0) continue; } - for (ord = u->orders; ord; ord = ord->next) { + for (ord = u->orders; ord; ord = ord->next) { if (get_keyword(ord) == K_RECRUIT) { if (recruit_archetypes()) { if (recruit_archetype(u, ord)>=0) { diff --git a/src/common/kernel/battle.c b/src/common/kernel/battle.c index 51f242201..50e70f8c6 100644 --- a/src/common/kernel/battle.c +++ b/src/common/kernel/battle.c @@ -3180,7 +3180,7 @@ simplename(region * r) static char name[17]; const char * cp = rname(r, NULL); for (i=0;*cp && i!=16;++i, ++cp) { - int c = *cp; + int c = *(unsigned char *)cp; while (c && !isalpha(c) && !isspace(c)) { ++cp; c = *(unsigned char*)cp; diff --git a/src/common/kernel/border.c b/src/common/kernel/border.c index aa37b2778..21b34f6d6 100644 --- a/src/common/kernel/border.c +++ b/src/common/kernel/border.c @@ -95,12 +95,13 @@ get_borders(const region * r1, const region * r2) border * new_border(border_type * type, region * from, region * to) { - border ** bp = get_borders_i(from, to); border * b = calloc(1, sizeof(struct border)); - while (*bp) bp = &(*bp)->next; - - *bp = b; + if (from && to) { + border ** bp = get_borders_i(from, to); + while (*bp) bp = &(*bp)->next; + *bp = b; + } b->type = type; b->from = from; b->to = to; @@ -113,26 +114,28 @@ new_border(border_type * type, region * from, region * to) void erase_border(border * b) { - border ** bp = get_borders_i(b->from, b->to); attrib ** ap = &b->attribs; while (*ap) a_remove(&b->attribs, *ap); - assert(*bp!=NULL || !"error: border is not registered"); - if (*bp==b) { - /* it is the first in the list, so it is in the nexthash list */ - if (b->next) { - *bp = b->next; - (*bp)->nexthash = b->nexthash; + if (b->from && b->to) { + border ** bp = get_borders_i(b->from, b->to); + assert(*bp!=NULL || !"error: border is not registered"); + if (*bp==b) { + /* it is the first in the list, so it is in the nexthash list */ + if (b->next) { + *bp = b->next; + (*bp)->nexthash = b->nexthash; + } else { + *bp = b->nexthash; + } } else { - *bp = b->nexthash; + while (*bp && *bp != b) { + bp = &(*bp)->next; + } + assert(*bp==b || !"error: border is not registered"); + *bp = b->next; } - } else { - while (*bp && *bp != b) { - bp = &(*bp)->next; - } - assert(*bp==b || !"error: border is not registered"); - *bp = b->next; } if (b->type->destroy) b->type->destroy(b); free(b); @@ -542,12 +545,10 @@ read_borders(FILE * f) } type = find_bordertype(zText); - if (from) { - if (type==NULL) { - log_error(("[read_borders] unknown border type %s in %s\n", zText, - regionname(from, NULL))); - assert(type || !"border type not registered"); - } + if (type==NULL) { + log_error(("[read_borders] unknown border type %s in %s\n", zText, + regionname(from, NULL))); + assert(type || !"border type not registered"); } if (to==from && type && from) { diff --git a/src/common/kernel/save.c b/src/common/kernel/save.c index 0668cabc8..00ff40ca9 100644 --- a/src/common/kernel/save.c +++ b/src/common/kernel/save.c @@ -1674,9 +1674,19 @@ readgame(const char * filename, int backup) } if (skip) { char * r; - char buffer[128]; +#define SKIPSIZE 4096 + char buffer[SKIPSIZE]; + buffer[SKIPSIZE-1] = '@'; do { r = fgets(buffer, sizeof(buffer), F); /* skip region */ + if (r && buffer[SKIPSIZE-1]!='@') { + while (r && buffer[SKIPSIZE-1]!='@') { + /* our buffer was not big enough */ + buffer[SKIPSIZE-1] = '@'; + r = fgets(buffer, sizeof(buffer), F); + } + if (r) continue; + } } while (r && buffer[0]!='\n'); continue; } diff --git a/src/common/util/attrib.c b/src/common/util/attrib.c index 2915efd3d..d79df3498 100644 --- a/src/common/util/attrib.c +++ b/src/common/util/attrib.c @@ -61,7 +61,7 @@ static attrib_type * at_find(unsigned int hk) { const char* translate[3][2] = { - { "zielregion", "targetregion" }, /* remapping: früher zielregion, heute targetregion */ + { "zielregion", "targetregion" }, /* remapping: from 'zielregion, heute targetregion */ { "verzaubert", "curse" }, /* remapping: früher verzaubert, jetzt curse */ { NULL, NULL } }; diff --git a/src/config.h b/src/config.h index c468c7cf4..c561de9fe 100644 --- a/src/config.h +++ b/src/config.h @@ -27,18 +27,25 @@ # pragma warning(disable: 4056) /* warning C4056: overflow in floating point constant arithmetic */ # pragma warning(disable: 4201) -/* warning C4201: Nicht dem Standard entsprechende Erweiterung : Struktur/Union ohne Namen */ +/* warning C4201: nonstandard extension used : nameless struct/union */ # pragma warning(disable: 4214) -/* warning C4214: Nicht dem Standard entsprechende Erweiterung : Basistyp fuer Bitfeld ist nicht int */ +/* warning C4214: nonstandard extension used : bit field types other than int */ # pragma warning(disable: 4100) /* warning C4100: : unreferenced formal parameter */ # pragma warning(disable: 4996) + /* warning C4100: was declared deprecated */ #ifndef _CRT_SECURE_NO_DEPRECATE # define _CRT_SECURE_NO_DEPRECATE #endif + +/* http://msdn2.microsoft.com/en-us/library/ms235505(VS.80).aspx */ +#ifndef _CRT_DISABLE_PERFCRIT_LOCKS +# define _CRT_DISABLE_PERFCRIT_LOCKS #endif +#endif /* _MSC_VER_ */ + #ifdef __cplusplus # include diff --git a/src/eressea/lua/message.cpp b/src/eressea/lua/message.cpp index 44d848867..feced4ac6 100644 --- a/src/eressea/lua/message.cpp +++ b/src/eressea/lua/message.cpp @@ -12,12 +12,15 @@ #include // lua includes +#pragma warning (push) +#pragma warning (disable: 4127) #include #include #include #if LUABIND_BETA >= 7 # include #endif +#pragma warning (pop) #include