diff --git a/polymer/eduke32/Makefile b/polymer/eduke32/Makefile index 6cde0edb6..6d4946aa5 100644 --- a/polymer/eduke32/Makefile +++ b/polymer/eduke32/Makefile @@ -205,7 +205,7 @@ ifeq (1,$(RELEASE)) endif endif -mapster32$(EXESUFFIX): $(EDITOROBJS) $(EOBJ)/$(EDITORLIB) $(EOBJ)/$(ENGINELIB) $(JAUDIOLIBDIR)/$(JAUDIOLIB) $(ENETDIR)/$(ENETLIB) +mapster32$(EXESUFFIX): $(EDITOROBJS) $(EOBJ)/$(EDITORLIB) $(EOBJ)/$(ENGINELIB) $(JAUDIOLIBDIR)/$(JAUDIOLIB) $(LINK_STATUS) if $(CC) $(CFLAGS) $(OURCFLAGS) -o $@ $^ $(LIBS) $(STDCPPLIB) $(MISCLINKOPTS); then $(LINK_OK); else $(LINK_FAILED); fi ifeq (1,$(RELEASE)) diff --git a/polymer/eduke32/build/include/build.h b/polymer/eduke32/build/include/build.h index 80bdf0f68..d5737579e 100644 --- a/polymer/eduke32/build/include/build.h +++ b/polymer/eduke32/build/include/build.h @@ -303,7 +303,7 @@ extern int32_t rendmode; EXTERN int32_t h_xsize[MAXTILES], h_ysize[MAXTILES]; EXTERN int8_t h_xoffs[MAXTILES], h_yoffs[MAXTILES]; -extern char *engineerrstr; +extern const char *engineerrstr; extern char noclip; EXTERN int32_t editorzrange[2]; diff --git a/polymer/eduke32/build/include/compat.h b/polymer/eduke32/build/include/compat.h index fccecdb9d..680f2e4ad 100644 --- a/polymer/eduke32/build/include/compat.h +++ b/polymer/eduke32/build/include/compat.h @@ -549,7 +549,7 @@ int32_t Bcorrectfilename(char *filename, int32_t removefn); int32_t Bcanonicalisefilename(char *filename, int32_t removefn); char *Bgetsystemdrives(void); int32_t Bfilelength(int32_t fd); -char *Bstrtoken(char *s, char *delim, char **ptrptr, int32_t chop); +char *Bstrtoken(char *s, const char *delim, char **ptrptr, int32_t chop); int32_t Bwildmatch (const char *i, const char *j); #if !defined(_WIN32) @@ -566,5 +566,8 @@ char *Bstrupr(char *); #define EDUKE32_TMRTIC t[ti++]=getticks() #define EDUKE32_TMRPRN do { int ii=0; fprintf(stderr,"%s: ",tmrstr); for (ii=1; ii=MAXCORRUPTTHINGS ? ">=":"", numcorruptthings); printext16(8,8, editorcolors[13],editorcolors[0],cbuf,0); } @@ -5274,7 +5275,11 @@ int32_t getpointhighlight(int32_t xplc, int32_t yplc, int32_t point) } if (dst <= dist) - dist = dst, closest = j; + { + // prefer white walls + if (dist=0)-(wall[closest].nextwall>=0) <= 0) + dist = dst, closest = j; + } } if (zoom >= 256) diff --git a/polymer/eduke32/build/src/cache1d.c b/polymer/eduke32/build/src/cache1d.c index 7d68973dd..5f945026b 100644 --- a/polymer/eduke32/build/src/cache1d.c +++ b/polymer/eduke32/build/src/cache1d.c @@ -69,7 +69,7 @@ static int32_t lockrecip[200]; static char toupperlookup[256]; -static void reportandexit(char *errormessage); +static void reportandexit(const char *errormessage); extern char pow2char[8]; @@ -226,7 +226,7 @@ void agecache(void) } } -static void reportandexit(char *errormessage) +static void reportandexit(const char *errormessage) { int32_t i, j; @@ -841,7 +841,7 @@ void kclose(int32_t handle) filehan[handle] = -1; } -static int32_t klistaddentry(CACHE1D_FIND_REC **rec, char *name, int32_t type, int32_t source) +static int32_t klistaddentry(CACHE1D_FIND_REC **rec, const char *name, int32_t type, int32_t source) { CACHE1D_FIND_REC *r = NULL, *attach = NULL; diff --git a/polymer/eduke32/build/src/compat.c b/polymer/eduke32/build/src/compat.c index ed1123e8d..427018ca2 100644 --- a/polymer/eduke32/build/src/compat.c +++ b/polymer/eduke32/build/src/compat.c @@ -707,7 +707,7 @@ int32_t Bclosedir(BDIR *dir) } -char *Bstrtoken(char *s, char *delim, char **ptrptr, int32_t chop) +char *Bstrtoken(char *s, const char *delim, char **ptrptr, int32_t chop) { char *p, *start; diff --git a/polymer/eduke32/build/src/defs.c b/polymer/eduke32/build/src/defs.c index 74d882b70..002a3a23a 100644 --- a/polymer/eduke32/build/src/defs.c +++ b/polymer/eduke32/build/src/defs.c @@ -82,7 +82,7 @@ enum scripttoken_t T_TILEFROMTEXTURE, T_XOFFSET, T_YOFFSET }; -typedef struct { char *text; int32_t tokenid; } tokenlist; +typedef struct { const char *text; int32_t tokenid; } tokenlist; static int32_t getatoken(scriptfile *sf, const tokenlist *tl, int32_t ntokens) { diff --git a/polymer/eduke32/build/src/engine.c b/polymer/eduke32/build/src/engine.c index ab0c1a302..27bc5e768 100644 --- a/polymer/eduke32/build/src/engine.c +++ b/polymer/eduke32/build/src/engine.c @@ -155,7 +155,7 @@ char britable[16][256]; // JBF 20040207: full 8bit precision extern char textfont[2048], smalltextfont[2048]; static char kensmessage[128]; -char *engineerrstr = "No error"; +const char *engineerrstr = "No error"; int32_t showfirstwall=0; int32_t showheightindicators=2; @@ -7912,7 +7912,7 @@ int32_t loadmaphack(const char *filename) T_LIGHT, }; - static struct { char *text; int32_t tokenid; } legaltokens[] = + static struct { const char *text; int32_t tokenid; } legaltokens[] = { { "sprite", T_SPRITE }, { "angleoff", T_ANGOFF }, @@ -9696,7 +9696,9 @@ int32_t lastwall(int16_t point) } -////////// +////////// CLIPMOVE ////////// + +int32_t clipmoveboxtracenum = 3; static int32_t clipsprite_try(const spritetype *spr, int32_t xmin, int32_t ymin, int32_t xmax, int32_t ymax) { @@ -9821,17 +9823,24 @@ static int32_t clipsprite_initindex(int32_t curidx, spritetype *curspr, int32_t return flipmul; } -#define addclipline(dax1, day1, dax2, day2, daoval) \ -{ \ - if (clipnum < MAXCLIPNUM) { \ - clipit[clipnum].x1 = dax1; clipit[clipnum].y1 = day1; \ - clipit[clipnum].x2 = dax2; clipit[clipnum].y2 = day2; \ - clipobjectval[clipnum] = daoval; \ - clipnum++; \ - } else if (!warned) { initprintf("!!clipnum\n"); warned=1; } \ -} \ - -int32_t clipmoveboxtracenum = 3; + +static int32_t clipmove_warned=0; + +static void addclipline(int32_t dax1, int32_t day1, int32_t dax2, int32_t day2, int32_t daoval) +{ + if (clipnum < MAXCLIPNUM) + { + clipit[clipnum].x1 = dax1; clipit[clipnum].y1 = day1; + clipit[clipnum].x2 = dax2; clipit[clipnum].y2 = day2; + clipobjectval[clipnum] = daoval; + clipnum++; + } + else if (!clipmove_warned) + { + initprintf("!!clipnum\n"); + clipmove_warned = 1; + } +} // // clipmove @@ -9852,11 +9861,13 @@ int32_t clipmove(vec3_t *vect, int16_t *sectnum, int32_t hitwall, cnt, clipyou; spritetype *curspr=NULL; // non-NULL when handling sprite with sector-like clipping - int32_t curidx=-1, warned=0, clipspritecnt; + int32_t curidx=-1, clipspritecnt; if (((xvect|yvect) == 0) || (*sectnum < 0)) return(0); retval = 0; + clipmove_warned = 0; + oxvect = xvect; oyvect = yvect; diff --git a/polymer/eduke32/samples/tests.m32 b/polymer/eduke32/samples/tests.m32 index 5dc737d2e..34f410e75 100644 --- a/polymer/eduke32/samples/tests.m32 +++ b/polymer/eduke32/samples/tests.m32 @@ -42,7 +42,9 @@ defstate arraytest ends defstate itertest -// iteration and break test + var gi gj gk + // iteration and break test + for i range 10 { addlogvar i @@ -82,70 +84,70 @@ define MIN_CONSTANT -2147483648 defstate consttest quote " --- Constants test ---", quote " " - quote "Shoud be 0:" + quote "Should be 0:" set i 0, set j TEST_ZERO qsprintf TQUOTE "%d %d %d %d" 0 TEST_ZERO i j quote TQUOTE, quote " " - quote "Shoud be 1:" + quote "Should be 1:" set i 1, set j TEST_PLUS_ONE qsprintf TQUOTE "%d %d %d %d" 1 TEST_PLUS_ONE i j quote TQUOTE, quote " " - quote "Shoud be -1:" + quote "Should be -1:" set i -1, set j TEST_MINUS_ONE qsprintf TQUOTE "%d %d %d %d" -1 TEST_MINUS_ONE i j quote TQUOTE, quote " " - quote "Shoud be 32767:" + quote "Should be 32767:" set i 32767, set j MOST_POSITIVE_DIRECT qsprintf TQUOTE "%d %d %d %d" 32767 MOST_POSITIVE_DIRECT i j quote TQUOTE, quote " " - quote "Shoud be -32768:" + quote "Should be -32768:" set i -32768, set j MOST_NEGATIVE_DIRECT qsprintf TQUOTE "%d %d %d %d" -32768 MOST_NEGATIVE_DIRECT i j quote TQUOTE, quote " " - quote "Shoud be 32768:" + quote "Should be 32768:" set i 32768, set j LEAST_POSITIVE_INDIRECT qsprintf TQUOTE "%d %d %d %d" 32768 LEAST_POSITIVE_INDIRECT i j quote TQUOTE, quote " " - quote "Shoud be -32769:" + quote "Should be -32769:" set i -32769, set j LEAST_NEGATIVE_INDIRECT qsprintf TQUOTE "%d %d %d %d" -32769 LEAST_NEGATIVE_INDIRECT i j quote TQUOTE, quote " " quote "Hex tests:" - quote "Shoud be 32767:" + quote "Should be 32767:" set i 0x7fff, set j HEX_MOST_POSITIVE_DIRECT qsprintf TQUOTE "%d %d %d %d" 0x7fff HEX_MOST_POSITIVE_DIRECT i j quote TQUOTE, quote " " - quote "Shoud be -32768:" + quote "Should be -32768:" set i 0xffff8000, set j HEX_MOST_NEGATIVE_DIRECT qsprintf TQUOTE "%d %d %d %d" 0xffff8000 HEX_MOST_NEGATIVE_DIRECT i j quote TQUOTE, quote " " - quote "Shoud be 32768:" + quote "Should be 32768:" set i 0x8000, set j HEX_LEAST_POSITIVE_INDIRECT qsprintf TQUOTE "%d %d %d %d" 0x8000 HEX_LEAST_POSITIVE_INDIRECT i j quote TQUOTE, quote " " - quote "Shoud be -32769:" + quote "Should be -32769:" set i 0xffff7fff, set j HEX_LEAST_NEGATIVE_INDIRECT qsprintf TQUOTE "%d %d %d %d" 0xffff7fff HEX_LEAST_NEGATIVE_INDIRECT i j quote TQUOTE, quote " " quote "min/max tests:" - quote "Shoud be 2147483647:" + quote "Should be 2147483647:" set i 2147483647, set j MAX_CONSTANT qsprintf TQUOTE "%d %d %d %d" 2147483647 MAX_CONSTANT i j quote TQUOTE, quote " " - quote "Shoud be -2147483648:" + quote "Should be -2147483648:" set i -2147483648, set j MIN_CONSTANT qsprintf TQUOTE "%d %d %d %d" -2147483648 MIN_CONSTANT i j quote TQUOTE, quote " " diff --git a/polymer/eduke32/samples/tiles.cfg b/polymer/eduke32/samples/tiles.cfg index 235194a33..a69fbeda7 100644 --- a/polymer/eduke32/samples/tiles.cfg +++ b/polymer/eduke32/samples/tiles.cfg @@ -3,8 +3,6 @@ #include "names.h" -// tilegroup "All named" with the hotkey "Y" is constructed automatically - tilegroup "Actors" { hotkey "A" diff --git a/polymer/eduke32/source/astub.c b/polymer/eduke32/source/astub.c index 95b3b9a8c..7c942ebdd 100644 --- a/polymer/eduke32/source/astub.c +++ b/polymer/eduke32/source/astub.c @@ -3788,7 +3788,7 @@ static inline void getnumber_doint64(int64_t *ptr, int32_t num) *ptr = (int64_t) num; } -void getnumberptr256(char *namestart, void *num, int32_t bytes, int32_t maxnumber, char sign, void *(func)(int32_t)) +static void getnumberptr256(const char *namestart, void *num, int32_t bytes, int32_t maxnumber, char sign, void *(func)(int32_t)) { char buffer[80], ch; int32_t n, danum = 0, oldnum; @@ -7090,8 +7090,8 @@ static void Keys2d(void) } else x=editorgridextent+1; - printmessage16("%s Corrupt %s %d%s", tsign<0?"<":">", secwalspr[j], i, - (x==editorgridextent+1) ? " (outside grid)" : (wrap ? " (wrap)" : "")); + printmessage16("#%d: %s Corrupt %s %d%s", curcorruptthing+1, tsign<0?"<":">", secwalspr[j], + i, (x==editorgridextent+1) ? " (outside grid)" : (wrap ? " (wrap)" : "")); } } else if (wallsprite==0) @@ -7346,7 +7346,7 @@ void ExtPreSaveMap(void) static void G_ShowParameterHelp(void) { - char *s = "Usage: mapster32 [OPTIONS] [FILE]\n\n" + const char *s = "Usage: mapster32 [OPTIONS] [FILE]\n\n" "-gFILE, -grp FILE\tUse extra group file FILE\n" "-hFILE\t\tUse definitions file FILE\n" "-jDIR, -game_dir DIR\n\t\tAdds DIR to the file path stack\n" @@ -7655,6 +7655,11 @@ int32_t ExtPreInit(int32_t argc,const char **argv) return 0; } +static int32_t atoi_safe(const char *str) +{ + return (int32_t)strtol(str, NULL, 10); +} + static int32_t osdcmd_quit(const osdfuncparm_t *parm) { UNREFERENCED_PARAMETER(parm); @@ -7784,7 +7789,7 @@ static int32_t osdcmd_vars_pk(const osdfuncparm_t *parm) OSD_Printf("Turning acceleration+declaration is %d\n", pk_turnaccel); else { - pk_turnaccel = atoi(parm->parms[0]); + pk_turnaccel = atoi_safe(parm->parms[0]); pk_turnaccel = pk_turnaccel<=pk_turndecel ? (pk_turndecel+1):pk_turnaccel; pk_turnaccel = pk_turnaccel>256 ? 256:pk_turnaccel; } @@ -7795,7 +7800,7 @@ static int32_t osdcmd_vars_pk(const osdfuncparm_t *parm) OSD_Printf("Turning deceleration is %d\n", pk_turndecel); else { - pk_turndecel = atoi(parm->parms[0]); + pk_turndecel = atoi_safe(parm->parms[0]); pk_turndecel = pk_turndecel<=0 ? 1:pk_turndecel; pk_turndecel = pk_turndecel>=pk_turnaccel ? (pk_turnaccel-1):pk_turndecel; pk_turndecel = pk_turndecel>128 ? 128:pk_turndecel; @@ -7810,7 +7815,7 @@ static int32_t osdcmd_vars_pk(const osdfuncparm_t *parm) { if (parm->numparms==1) { - pk_uedaccel = atoi(parm->parms[0]); + pk_uedaccel = atoi_safe(parm->parms[0]); pk_uedaccel = pk_uedaccel<0 ? 0:pk_uedaccel; pk_uedaccel = pk_uedaccel>5 ? 5:pk_uedaccel; } @@ -7843,7 +7848,7 @@ static int32_t osdcmd_vars_pk(const osdfuncparm_t *parm) static const char *how[3] = {"none", "two-sided walls only", "all"}; if (parm->numparms == 1) - showheightindicators = clamp(atoi(parm->parms[0]), 0, 2); + showheightindicators = clamp(atoi_safe(parm->parms[0]), 0, 2); if (parm->numparms <= 1) OSD_Printf("height indicators: %s\n", how[showheightindicators]); @@ -7855,7 +7860,7 @@ static int32_t osdcmd_vars_pk(const osdfuncparm_t *parm) static const char *how[3] = {"none", "current sector only", "all"}; if (parm->numparms == 1) - showambiencesounds = clamp(atoi(parm->parms[0]), 0, 2); + showambiencesounds = clamp(atoi_safe(parm->parms[0]), 0, 2); if (parm->numparms <= 1) OSD_Printf("ambience sound circles: %s\n", how[showambiencesounds]); @@ -7864,7 +7869,9 @@ static int32_t osdcmd_vars_pk(const osdfuncparm_t *parm) } else if (!Bstrcasecmp(parm->name, "corruptcheck")) { - if (parm->numparms == 1) + int32_t tryfix = parm->numparms>=1 && !Bstrcasecmp(parm->parms[0], "tryfix"); + + if (parm->numparms == 1 || tryfix) { if (!Bstrcasecmp(parm->parms[0], "now")) { @@ -7872,14 +7879,47 @@ static int32_t osdcmd_vars_pk(const osdfuncparm_t *parm) OSD_Printf("All OK.\n"); return OSDCMD_OK; } - else if (!Bstrcasecmp(parm->parms[0], "tryfix")) + else if (tryfix) { - CheckMapCorruption(3, 1); + uint64_t whicherrs = parm->numparms==1 ? ULONG_LONG_MAX : 0; + + if (whicherrs==0) + { + int32_t i, n, m; + char *endptr; + for (i=1; inumparms; i++) + { + n = (int32_t)Bstrtol(parm->parms[i], &endptr, 10); + if (endptr != parm->parms[i]) + { + if (*endptr=='-') + { + m = (int32_t)Bstrtol(endptr+1, NULL, 10); + if (n>=1 && n<=m && m<=MAXCORRUPTTHINGS) + { + uint64_t mask = ULONG_LONG_MAX; + m = m-n+1; + mask >>= (MAXCORRUPTTHINGS-m); + mask <<= (n-1); + + whicherrs |= mask; + } + } + else + { + if (n>=1 && n<=MAXCORRUPTTHINGS) + whicherrs |= (1ull<<(n-1)); + } + } + } + } + + CheckMapCorruption(3, whicherrs); return OSDCMD_OK; } else if (isdigit(parm->parms[0][0])) { - autocorruptcheck = clamp(atoi(parm->parms[0]), 0, 3600); + autocorruptcheck = clamp(atoi_safe(parm->parms[0]), 0, 3600); corruptchecktimer = totalclock + 120*autocorruptcheck; } } @@ -7891,7 +7931,7 @@ static int32_t osdcmd_vars_pk(const osdfuncparm_t *parm) else OSD_Printf("auto corruption check: off\n"); } - else + else if (!tryfix) return OSDCMD_SHOWHELP; } @@ -7906,7 +7946,7 @@ static int32_t osdcmd_tint(const osdfuncparm_t *parm) if (parm->numparms==1) { - i = atoi(parm->parms[0]); + i = atoi_safe(parm->parms[0]); if (i>=0 && inumparms>=2) { - i = atoi(parm->parms[0]); + i = atoi_safe(parm->parms[0]); if (i<0 || i>=MAXPALOOKUPS-RESERVEDPALS) return OSDCMD_SHOWHELP; p = &hictinting[i]; - p->r = atoi(parm->parms[1]); - p->g = (parm->numparms>=3) ? atoi(parm->parms[2]) : 255; - p->b = (parm->numparms>=4) ? atoi(parm->parms[3]) : 255; - p->f = (parm->numparms>=5) ? atoi(parm->parms[4])&HICEFFECTMASK : 0; + p->r = atoi_safe(parm->parms[1]); + p->g = (parm->numparms>=3) ? atoi_safe(parm->parms[2]) : 255; + p->b = (parm->numparms>=4) ? atoi_safe(parm->parms[3]) : 255; + p->f = (parm->numparms>=5) ? atoi_safe(parm->parms[4])&HICEFFECTMASK : 0; } return OSDCMD_OK; } @@ -7965,7 +8005,7 @@ static int32_t osdcmd_disasm(const osdfuncparm_t *parm) if (!isdigit(parm->parms[1][0])) return OSDCMD_SHOWHELP; - i=atoi(parm->parms[1]); + i=atoi_safe(parm->parms[1]); if (parm->parms[0][0]=='s') { @@ -8122,7 +8162,7 @@ static int32_t osdcmd_endisableevent(const osdfuncparm_t *parm) if (isdigit(parm->parms[i][0])) { - j = atoi(parm->parms[i]); + j = atoi_safe(parm->parms[i]); Bsprintf(buf2, "event %d", j); } else if (!Bstrncmp(parm->parms[i], "EVENT_", 6)) @@ -8349,12 +8389,12 @@ enum typedef struct { - char *text; + const char *text; int32_t tokenid; } tokenlist; -static int32_t getatoken(scriptfile *sf, tokenlist *tl, int32_t ntokens) +static int32_t getatoken(scriptfile *sf, const tokenlist *tl, int32_t ntokens) { char *tok; int32_t i; @@ -8466,7 +8506,7 @@ int32_t parsegroupfiles(scriptfile *script) return 0; } -int32_t loadgroupfiles(char *fn) +int32_t loadgroupfiles(const char *fn) { scriptfile *script; @@ -10038,48 +10078,57 @@ void ExtCheckKeys(void) //// port of a.m32's corruptchk //// // returns value from 0 (all OK) to 5 (panic!) #define CCHK_PANIC OSDTEXT_DARKRED "PANIC!!!^O " -#define CCHKPREF OSDTEXT_RED "* ^O" +//#define CCHKPREF OSDTEXT_RED "^O" #define CCHK_CORRECTED OSDTEXT_GREEN " -> " #define CORRUPTCHK_PRINT(errlev, what, fmt, ...) do \ { \ bad = max(bad, errlev); \ - if (numcorruptthings=MAXCORRUPTTHINGS) \ + goto too_many_errors; \ + corruptthings[numcorruptthings++] = what; \ if (errlev >= printfromlev) \ - OSD_Printf(CCHKPREF fmt "\n", ## __VA_ARGS__); \ + OSD_Printf("#%d: " fmt "\n", numcorruptthings, ## __VA_ARGS__); \ } while (0) +static int32_t walls_are_consistent(int32_t nw, int32_t j) +{ + return (wall[j].x==POINT2(nw).x && wall[j].y==POINT2(nw).y + && POINT2(j).x==wall[nw].x && POINT2(j).y==wall[nw].y); +} + static void suggest_nextsector_correction(int32_t nw, int32_t j) { if (nw>=0 && nw=0 && nw numwalls) CORRUPTCHK_PRINT(4, CORRUPT_SECTOR|i, "SECTOR[%d]: wallptr+wallnum=%d out of range: numwalls=%d", i, endwall, numwalls); - if (bad) - errlevel = max(errlevel, bad); - else + errlevel = max(errlevel, bad); + + if (bad<4) { endwall--; @@ -10162,11 +10211,15 @@ int32_t CheckMapCorruption(int32_t printfromlev, int32_t tryfixing) { if (!bad) { + int32_t onumct = numcorruptthings; CORRUPTCHK_PRINT(4, CORRUPT_WALL|j, "WALL[%d].NEXTSECTOR is its own sector", j); - if (tryfixing) - do_nextsector_correction(nw, j); - else if (4>=printfromlev) - suggest_nextsector_correction(nw, j); + if (onumct < MAXCORRUPTTHINGS) + { + if (tryfixing & (1ull<=printfromlev) + suggest_nextsector_correction(nw, j); + } } } @@ -10175,15 +10228,16 @@ int32_t CheckMapCorruption(int32_t printfromlev, int32_t tryfixing) if (seen_nextwalls[nw>>3]&(1<<(nw&7))) { int16_t nwnw, lnws; + int32_t onumct = numcorruptthings; lnws = lastnextwallsource[nw]; CORRUPTCHK_PRINT(3, CORRUPT_WALL|j, "WALL[%d].NEXTWALL=%d already referenced from wall %d", j, nw, lnws); nwnw = wall[nw].nextwall; - if (nwnw==j || nwnw==lnws) + if (onumct < MAXCORRUPTTHINGS && (nwnw==j || nwnw==lnws)) { int32_t walltoclear = nwnw==j ? lnws : j; - if (tryfixing) + if (tryfixing & (1ull<=printfromlev) - suggest_nextsector_correction(nw, j); + if (onumct < MAXCORRUPTTHINGS) + { + if (tryfixing & (1ull<=printfromlev) + suggest_nextsector_correction(nw, j); + } } else if (ns>=0) { @@ -10218,13 +10276,16 @@ int32_t CheckMapCorruption(int32_t printfromlev, int32_t tryfixing) { CORRUPTCHK_PRINT(4, CORRUPT_WALL|j, "WALL[%d].NEXTWALL=%d out of .NEXTSECTOR=%d's bounds", j, nw, ns); - if (tryfixing) - do_nextsector_correction(nw, j); - else if (4 >= printfromlev) + if (onumct < MAXCORRUPTTHINGS) { - OSD_Printf(" sector %d's walls: [%d .. %d]\n", ns, sector[ns].wallptr, - sector[ns].wallptr+sector[ns].wallnum-1); - suggest_nextsector_correction(nw, j); + if (tryfixing & (1ull<= printfromlev) + { + OSD_Printf(" sector %d's walls: [%d .. %d]\n", ns, + sector[ns].wallptr, sector[ns].wallptr+sector[ns].wallnum-1); + suggest_nextsector_correction(nw, j); + } } } } @@ -10251,6 +10312,13 @@ int32_t CheckMapCorruption(int32_t printfromlev, int32_t tryfixing) } } + if (0) + { +too_many_errors: + if (printfromlev<=errlevel) + OSD_Printf("!! too many errors, stopping. !!\n"); + } + errlevel = max(errlevel, bad); if (errlevel) @@ -10259,8 +10327,11 @@ int32_t CheckMapCorruption(int32_t printfromlev, int32_t tryfixing) OSD_Printf("-- corruption level: %d\n", errlevel); } - Bfree(seen_nextwalls); - Bfree(lastnextwallsource); + if (seen_nextwalls) + { + Bfree(seen_nextwalls); + Bfree(lastnextwallsource); + } corruptlevel = errlevel; @@ -10506,7 +10577,7 @@ static void EditSectorData(int16_t sectnum) break; } } - if (col == 2) + else if (col == 2) { switch (row) { @@ -10606,10 +10677,10 @@ static void EditWallData(int16_t wallnum) { Bsprintf(med_edittext,"Wall %d X Repeat: ",wallnum); printmessage16("%s", med_edittext); - wall[wallnum].xrepeat = (char)getnumber16(med_edittext,(int32_t)wall[wallnum].xrepeat,256L,0); + wall[wallnum].xrepeat = (char)getnumber16(med_edittext,(int32_t)wall[wallnum].xrepeat,255,0); Bsprintf(med_edittext,"Wall %d Y Repeat: ",wallnum); printmessage16("%s", med_edittext); - wall[wallnum].yrepeat = (char)getnumber16(med_edittext,(int32_t)wall[wallnum].yrepeat,256L,0); + wall[wallnum].yrepeat = (char)getnumber16(med_edittext,(int32_t)wall[wallnum].yrepeat,255,0); } break; case 4: @@ -10618,10 +10689,10 @@ static void EditWallData(int16_t wallnum) { Bsprintf(med_edittext,"Wall %d X Pan: ",wallnum); printmessage16("%s", med_edittext); - wall[wallnum].xpanning = (char)getnumber16(med_edittext,(int32_t)wall[wallnum].xpanning,256L,0); + wall[wallnum].xpanning = (char)getnumber16(med_edittext,(int32_t)wall[wallnum].xpanning,255,0); Bsprintf(med_edittext,"Wall %d Y Pan: ",wallnum); printmessage16("%s", med_edittext); - wall[wallnum].ypanning = (char)getnumber16(med_edittext,(int32_t)wall[wallnum].ypanning,256L,0); + wall[wallnum].ypanning = (char)getnumber16(med_edittext,(int32_t)wall[wallnum].ypanning,255,0); } break; case 5: @@ -10889,7 +10960,7 @@ static void GenericSpriteSearch() int32_t rowmax[3]= {6,5,6}, dispwidth[3] = {24,24,28}; int32_t xpos[3] = {8,200,400}, ypos = ydim-STATUS2DSIZ+48; - static char *labels[7][3] = + static const char *labels[7][3] = { {"X-coordinate", "Flags (hex)", "Angle (2048 degrees)"}, {"Y-coordinate", "Shade", "X-Velocity"}, diff --git a/polymer/eduke32/source/m32def.c b/polymer/eduke32/source/m32def.c index 2179f1af9..231118a95 100644 --- a/polymer/eduke32/source/m32def.c +++ b/polymer/eduke32/source/m32def.c @@ -909,6 +909,26 @@ static int32_t GetGamearrayID(const char *szGameLabel, int32_t searchlocals) #define GV_WRITABLE GAMEVAR_READONLY #define GV_SIMPLE GAMEVAR_SPECIAL +static int32_t parse_integer_literal(int32_t *num) +{ + if (tolower(textptr[1])=='x') + sscanf(textptr+2, "%" SCNx32, num); + else + { + long lnum; + errno = 0; + lnum = strtol(textptr, NULL, 10); + if (errno || (sizeof(long)>4 && (lnumINT_MAX))) + { + C_CUSTOMERROR("integer literal exceeds bitwidth."); + return 1; + } + *num = (int32_t)lnum; + } + + return 0; +} + static void C_GetNextVarType(int32_t type) { int32_t i, id=0, flags=0, num, indirect=0; //, thenum; @@ -940,13 +960,10 @@ static void C_GetNextVarType(int32_t type) // if (!(g_numCompilerErrors || g_numCompilerWarnings) && g_scriptDebug) // initprintf("%s:%d: debug: accepted constant %d in place of gamevar.\n",g_szScriptFileName,g_lineNumber,atol(textptr)); - if (tolower(textptr[1])=='x') - sscanf(textptr+2, "%" SCNx32, &num); - else - num = atoi(textptr); + parse_integer_literal(&num); //thenum=num; if (type==GV_SIMPLE && (num<0 || num>=65536)) - C_CUSTOMERROR("array index %d out of bounds. (max: 65535)", num); + C_CUSTOMERROR("array index %d out of bounds. (max: 65535)", num); if (g_numCompilerErrors==0 && type!=GV_SIMPLE && num != (int16_t)num) { @@ -1442,10 +1459,7 @@ static int32_t C_GetNextValue(int32_t type) // if (!(g_numCompilerErrors || g_numCompilerWarnings) && g_scriptDebug > 1) // initprintf("%s:%d: debug: accepted constant %d.\n",g_szScriptFileName,g_lineNumber,atol(textptr)); - if (tolower(textptr[1])=='x') - sscanf(textptr+2,"%" SCNx32 "",g_scriptPtr); - else - *g_scriptPtr = atol(textptr); + parse_integer_literal(g_scriptPtr); g_scriptPtr++; diff --git a/polymer/eduke32/source/m32def.h b/polymer/eduke32/source/m32def.h index 1a3c0b816..9da93f7df 100644 --- a/polymer/eduke32/source/m32def.h +++ b/polymer/eduke32/source/m32def.h @@ -70,7 +70,7 @@ extern int32_t g_stateCount; typedef struct { - char *name; + const char *name; int16_t lId; int16_t flags; // 1: read-only int32_t min, max; @@ -82,7 +82,8 @@ extern const memberlabel_t SpriteLabels[]; typedef struct { - char* token; int32_t val; + const char* token; + int32_t val; } tokenmap_t; extern const tokenmap_t iter_tokens[]; diff --git a/polymer/eduke32/source/m32exec.c b/polymer/eduke32/source/m32exec.c index 472583b42..7989b7359 100644 --- a/polymer/eduke32/source/m32exec.c +++ b/polymer/eduke32/source/m32exec.c @@ -440,9 +440,11 @@ skip_check: //AddLog("Done Executing Case"); bMatched=1; } + if (right-left < 0) break; } + if (!bMatched) { if (*lpDefault >= 0) diff --git a/polymer/eduke32/source/mapster32.h b/polymer/eduke32/source/mapster32.h index 33d9c2637..7695f9c09 100644 --- a/polymer/eduke32/source/mapster32.h +++ b/polymer/eduke32/source/mapster32.h @@ -26,7 +26,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // #define VULGARITY -char *defsfilename = "duke3d.def"; +const char *defsfilename = "duke3d.def"; extern char keystatus[]; extern int16_t defaultspritecstat; diff --git a/polymer/eduke32/source/savegame.c b/polymer/eduke32/source/savegame.c index 63f247fa2..d55248c87 100644 --- a/polymer/eduke32/source/savegame.c +++ b/polymer/eduke32/source/savegame.c @@ -937,7 +937,7 @@ static uint8_t savegame_comprthres; // 64 #define DS_LOADFN 128 // .ptr is function that is run when loading #define DS_SAVEFN 256 // .ptr is function that is run when saving -#define DS_NOCHK 1024 // don't check for diffs (and don't write out in dump) since assumend constant throughout demo +#define DS_NOCHK 1024 // don't check for diffs (and don't write out in dump) since assumed constant throughout demo #define DS_END (0x70000000) static int32_t ds_getcnt(const dataspec_t *sp) diff --git a/polymer/eduke32/source/sdlmusic.c b/polymer/eduke32/source/sdlmusic.c index 04abe0a33..aa3e44b5d 100644 --- a/polymer/eduke32/source/sdlmusic.c +++ b/polymer/eduke32/source/sdlmusic.c @@ -226,7 +226,7 @@ fallback: } { - static char *s[] = { "/etc/timidity.cfg", "/etc/timidity/timidity.cfg", "/etc/timidity/freepats.cfg" }; + static const char *s[] = { "/etc/timidity.cfg", "/etc/timidity/timidity.cfg", "/etc/timidity/freepats.cfg" }; FILE *fp; int32_t i;