diff options
author | James Brown | 2002-03-10 17:33:04 +0000 |
---|---|---|
committer | James Brown | 2002-03-10 17:33:04 +0000 |
commit | 87ac8ae487a32f3e484846771b308bd548bc4814 (patch) | |
tree | c78be5f6357f3e3d91cfd7ecab0f5b7626419fa5 | |
parent | 31dc24a037f9673441cf7a5295138b89c9d6d911 (diff) | |
download | scummvm-rg350-87ac8ae487a32f3e484846771b308bd548bc4814.tar.gz scummvm-rg350-87ac8ae487a32f3e484846771b308bd548bc4814.tar.bz2 scummvm-rg350-87ac8ae487a32f3e484846771b308bd548bc4814.zip |
Apply some patches by syke to prevent buffer overruns, etc.
svn-id: r3723
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | actor.cpp | 2 | ||||
-rw-r--r-- | debug.cpp | 6 | ||||
-rw-r--r-- | gfx.cpp | 2 | ||||
-rw-r--r-- | gui.cpp | 2 | ||||
-rw-r--r-- | insane.cpp | 4 | ||||
-rw-r--r-- | object.cpp | 2 | ||||
-rw-r--r-- | resource.cpp | 6 | ||||
-rw-r--r-- | script.cpp | 4 | ||||
-rw-r--r-- | script_v1.cpp | 9 | ||||
-rw-r--r-- | scumm.h | 27 | ||||
-rw-r--r-- | scummsys.h | 12 | ||||
-rw-r--r-- | scummvm.cpp | 4 | ||||
-rw-r--r-- | sdl.cpp | 2 | ||||
-rw-r--r-- | sys.cpp | 1 | ||||
-rw-r--r-- | windows.cpp | 2 |
16 files changed, 45 insertions, 42 deletions
@@ -1,7 +1,7 @@ # $Header$ CC = gcc -CFLAGS = -g -Wno-multichar +CFLAGS = -g -Wall -Wstrict-prototypes -Wno-long-long -Wno-multichar DEFINES = -DUNIX -DUSE_ADLIB LDFLAGS := INCLUDES:= `sdl-config --cflags` -I./ -I./sound @@ -977,7 +977,7 @@ void Scumm::actorTalk() { _msgPtrToAdd = charset._buffer; _messagePtr = addMessageToStack(_messagePtr); - assert(_msgPtrToAdd - charset._buffer < sizeof(charset._buffer)); + assert((int)(_msgPtrToAdd - charset._buffer) < (int)(sizeof(charset._buffer))); if (_actorToPrintStrFor==0xFF) { if (!_keepText) @@ -110,7 +110,7 @@ bool ScummDebugger::do_command() { return true; case CMD_DUMPBOX: { - int num, i = 0, rows = 0; + int num, i = 0; BoxCoords box; byte *boxm = _s->getBoxMatrixBaseAddr(); num = _s->getNumBoxes(); @@ -206,11 +206,11 @@ static const DebuggerCommands debugger_commands[] = { { "a", 1, CMD_ACTOR }, { "s", 1, CMD_SCRIPTS }, { "r", 1, CMD_LOAD_ROOM }, - { "b", 1, CMD_DUMPBOX}, + { "b", 1, CMD_DUMPBOX}, { "v", 1, CMD_VAR}, { "w", 1, CMD_WATCH}, { "e", 1, CMD_EXIT }, - { 0, 0, 0 }, + { "" , 0, 0 } }; int ScummDebugger::get_command() { @@ -940,7 +940,7 @@ void Gdi::decompressMaskImgOr() { void Scumm::redrawBGStrip(int start, int num) { int s = _screenStartStrip + start; - assert(s>=0 && s<sizeof(gfxUsageBits)/sizeof(gfxUsageBits[0])); + assert(s>=0 && (size_t)s<sizeof(gfxUsageBits)/sizeof(gfxUsageBits[0])); _curVirtScreen = &virtscr[0]; @@ -33,7 +33,7 @@ void Gui::draw(int start,int end) { if (end==-1) end=start; - for (i=0; i<sizeof(_widgets) / sizeof(_widgets[0]); i++) { + for (i=0; i<(int)(sizeof(_widgets) / sizeof(_widgets[0])); i++) { const GuiWidget *w = _widgets[i]; if (w) { _parentX = 0; diff --git a/insane.cpp b/insane.cpp index 0f1fb0dda0..095714c007 100644 --- a/insane.cpp +++ b/insane.cpp @@ -594,7 +594,7 @@ void codec37_maketable(PersistentCodecData37 *pcd, int pitch, byte idx) { - assert(idx*255 + 254 < sizeof(maketable_bytes)/2); + assert(idx*255 + 254 < (int)(sizeof(maketable_bytes)/2)); @@ -618,7 +618,7 @@ void codec37(CodecData *cd, PersistentCodecData37 *pcd) { int src_pitch; - byte *src = cd->src, *curbuf; + byte *curbuf; uint size; diff --git a/object.cpp b/object.cpp index 08f717bf18..df857cbb6b 100644 --- a/object.cpp +++ b/object.cpp @@ -654,7 +654,7 @@ void Scumm::removeObjectFromRoom(int obj) { void Scumm::addObjectToDrawQue(int object) { _drawObjectQue[_drawObjectQueNr++] = object; - if (_drawObjectQueNr > sizeof(_drawObjectQue)/sizeof(_drawObjectQue[0])) + if ((unsigned int)_drawObjectQueNr > sizeof(_drawObjectQue)/sizeof(_drawObjectQue[0])) error("Draw Object Que overflow"); } diff --git a/resource.cpp b/resource.cpp index 9a2b806fe6..4edc81158a 100644 --- a/resource.cpp +++ b/resource.cpp @@ -55,7 +55,7 @@ void Scumm::openRoom(int room) { room_offs = room ? _roomFileOffsets[room] : 0; #endif - if (room_offs == 0xFFFFFFFF) + if (room_offs == (int)0xFFFFFFFF) break; if (room_offs != 0 && room != 0) { @@ -495,7 +495,7 @@ void Scumm::readResTypeList(int id, uint32 tag, const char *name) { void Scumm::allocResTypeData(int id, uint32 tag, int num, const char *name, int mode) { debug(9, "allocResTypeData(%d,%x,%d,%s,%d)",id,FROM_LE_32(tag),num,name,mode); - assert(id>=0 && id<sizeof(res.mode)/sizeof(res.mode[0])); + assert(id>=0 && id<(int)(sizeof(res.mode)/sizeof(res.mode[0]))); if (num>=2000) { error("Too many %ss (%d) in directory", name, num); @@ -1099,7 +1099,7 @@ void Scumm::resourceStats() { } } - printf("Total allocated size=%d, locked=%d(%d)\n", _allocatedSize, lockedSize, lockedNum); + printf("Total allocated size=%ld, locked=%ld(%ld)\n", _allocatedSize, lockedSize, lockedNum); } void Scumm::heapClear(int mode) { diff --git a/script.cpp b/script.cpp index d50adc9566..9d5a8b2ef8 100644 --- a/script.cpp +++ b/script.cpp @@ -732,12 +732,12 @@ int Scumm::getVerbEntrypoint(int obj, int entry) { void Scumm::push(int a) { - assert(_scummStackPos >=0 && _scummStackPos <= ARRAYSIZE(_scummStack)); + assert(_scummStackPos >=0 && (unsigned int)_scummStackPos <= ARRAYSIZE(_scummStack)); _scummStack[_scummStackPos++] = a; } int Scumm::pop() { - assert(_scummStackPos >0 && _scummStackPos <= ARRAYSIZE(_scummStack)); + assert(_scummStackPos >0 && (unsigned int)_scummStackPos <= ARRAYSIZE(_scummStack)); return _scummStack[--_scummStackPos]; } diff --git a/script_v1.cpp b/script_v1.cpp index b881cca4cb..fefc32dc57 100644 --- a/script_v1.cpp +++ b/script_v1.cpp @@ -1035,7 +1035,7 @@ void Scumm::o5_drawObject() { if (_features & GF_SMALL_HEADER) { int temp = getVarOrDirectWord(0x40); - int room = getVarOrDirectWord(0x20); + getVarOrDirectWord(0x20); // Room idx = getObjectIndex(obj); if(idx==-1) @@ -1850,7 +1850,7 @@ void Scumm::o5_roomOps() { char buf[256],*s; a = getVarOrDirectByte(0x80); s = buf; - while (*s++=fetchScriptByte()); + while ((*s++=fetchScriptByte())); warning("roomops:13 save-string(%d,\"%s\") not implemented", a, buf); break; } @@ -1858,7 +1858,7 @@ void Scumm::o5_roomOps() { char buf[256],*s; a = getVarOrDirectByte(0x80); s = buf; - while (*s++=fetchScriptByte()); + while ((*s++=fetchScriptByte())); warning("roomops:14 load-string(%d,\"%s\") not implemented", a, buf); break; case 15: /* palmanip? */ @@ -2364,7 +2364,8 @@ void Scumm::o5_walkActorToObject() { int Scumm::getWordVararg(int16 *ptr) { int i; - for (i=0; i<16; i++) + + for (i=0; i<15; i++) ptr[i] = 0; i = 0; @@ -99,8 +99,10 @@ struct MemBlkHeader { }; -#pragma START_PACK_STRUCTS - +#if !defined(__GNUC__) + #pragma START_PACK_STRUCTS +#endif + #define SIZEOF_BOX 20 struct Box { /* file format */ int16 ulx,uly; @@ -219,7 +221,10 @@ struct ImageHeader { /* file format */ } GCC_PACK v7; } GCC_PACK; } GCC_PACK; -#pragma END_PACK_STRUCTS + +#if !defined(__GNUC__) + #pragma END_PACK_STRUCTS +#endif struct AdjustBoxResult { int16 x,y; @@ -361,7 +366,7 @@ enum ResTypes { rtBox = 15, rtObjectName = 16, rtLast = 16, - rtNumTypes = 17, + rtNumTypes = 17 }; enum { @@ -375,7 +380,7 @@ enum { enum { CM_NORMAL = 1, CM_FOLLOW_ACTOR = 2, - CM_PANNING = 3, + CM_PANNING = 3 }; enum { @@ -395,7 +400,7 @@ enum MoveFlags { MF_NEW_LEG = 1, MF_IN_LEG = 2, MF_TURN = 4, - MF_LAST_LEG = 8, + MF_LAST_LEG = 8 }; #define _maxRooms res.num[rtRoom] @@ -745,7 +750,7 @@ struct Gdi { enum DrawBitmapFlags { dbAllowMaskOr = 1, dbDrawMaskOnBoth = 2, - dbClear = 4, + dbClear = 4 }; }; @@ -792,7 +797,7 @@ enum GameId { GID_INDY3_256 = 9, GID_LOOM = 10, GID_FT = 11, - GID_DIG = 12, + GID_DIG = 12 }; enum GameFeatures { @@ -814,7 +819,7 @@ enum GameFeatures { GF_16COLOR = 256, GF_OLD256 = 512, GF_AUDIOTRACKS = 1024, - GF_NO_SCALLING = 2048, + GF_NO_SCALLING = 2048 }; struct ScummDebugger; @@ -1941,7 +1946,7 @@ struct Scumm { enum FindObjectWhat { foCodeHeader = 1, foImageHeader = 2, - foCheckAlreadyLoaded = 4, + foCheckAlreadyLoaded = 4 }; void findObjectInRoom(FindObjectInRoom *fo, byte findWhat, uint object, uint room); @@ -2170,7 +2175,7 @@ enum AkosOpcodes{ AKC_JumpLE = 0xC093, AKC_JumpG = 0xC094, AKC_JumpGE = 0xC095, - AKC_ClearFlag = 0xC09F, + AKC_ClearFlag = 0xC09F }; diff --git a/scummsys.h b/scummsys.h index da2ae4fed9..6a4b5f9ef1 100644 --- a/scummsys.h +++ b/scummsys.h @@ -236,31 +236,31 @@ typedef signed long int32; #define MKID(a) ((((a)>>24)&0xFF) | (((a)>>8)&0xFF00) | (((a)<<8)&0xFF0000) | (((a)<<24)&0xFF000000)) #if defined(SCUMM_NEED_ALIGNMENT) - uint FORCEINLINE READ_LE_UINT16(void *ptr) { + FORCEINLINE uint READ_LE_UINT16(void *ptr) { return (((byte*)ptr)[1]<<8)|((byte*)ptr)[0]; } #else - uint FORCEINLINE READ_LE_UINT16(void *ptr) { + FORCEINLINE uint READ_LE_UINT16(void *ptr) { return *(uint16*)(ptr); } #endif -uint FORCEINLINE READ_BE_UINT16(void *ptr) { +FORCEINLINE uint READ_BE_UINT16(void *ptr) { return (((byte*)ptr)[0]<<8)|((byte*)ptr)[1]; } #if defined(SCUMM_NEED_ALIGNMENT) - uint32 FORCEINLINE READ_LE_UINT32(void *ptr) { + FORCEINLINE uint32 READ_LE_UINT32(void *ptr) { byte *b = (byte*)ptr; return (b[3]<<24)+(b[2]<<16)+(b[1]<<8)+(b[0]); } #else - uint32 FORCEINLINE READ_LE_UINT32(void *ptr) { + FORCEINLINE uint32 READ_LE_UINT32(void *ptr) { return *(uint32*)(ptr); } #endif -uint32 FORCEINLINE READ_BE_UINT32(void *ptr) { +FORCEINLINE uint32 READ_BE_UINT32(void *ptr) { byte *b = (byte*)ptr; return (b[0]<<24)+(b[1]<<16)+(b[2]<<8)+(b[3]); } diff --git a/scummvm.cpp b/scummvm.cpp index 48ab2a882a..69d4acdfb0 100644 --- a/scummvm.cpp +++ b/scummvm.cpp @@ -855,7 +855,7 @@ void Scumm::initRoomSubBlocks() { searchptr = roomptr = getResourceAddress(rtRoom, _roomResource); if(_features & GF_SMALL_HEADER) { while( (ptr = findResourceSmall(MKID('LSCR'), searchptr)) != NULL ) { - int id; + int id = 0; ptr += _resourceHeaderSize; /* skip tag & size */ #ifdef DUMP_SCRIPTS do { @@ -870,7 +870,7 @@ void Scumm::initRoomSubBlocks() { } } else { while( (ptr = findResource(MKID('LSCR'), searchptr)) != NULL ) { - int id; + int id = 0; ptr += _resourceHeaderSize; /* skip tag & size */ @@ -658,8 +658,6 @@ void drawMouse(Scumm *s, int xdraw, int ydraw, int w, int h, byte *buf, bool vis } } -static uint32 midi_counter; - void fill_sound(void *userdata, Uint8 *stream, int len) { scumm.mixWaves((int16*)stream, len>>1); } @@ -51,7 +51,6 @@ void Scumm::clearFileReadFailed(void *file) { } bool Scumm::fileEof(void *file) { - FILE *a = (FILE*)file; return feof((FILE*)file) != 0; } diff --git a/windows.cpp b/windows.cpp index 7890054c27..5d43000ce4 100644 --- a/windows.cpp +++ b/windows.cpp @@ -507,9 +507,9 @@ DWORD _stdcall WndMan::sound_thread(WndMan *wm) { int time = GetTickCount(), cur; while (1) { + cur = GetTickCount(); if (!snd_driv.wave_based()) { - cur = GetTickCount(); while (time < cur) { sound.on_timer(); time += 10; |