diff --git a/source/glest_game/game/script_manager.cpp b/source/glest_game/game/script_manager.cpp index 6fadac37..ccf80d3e 100644 --- a/source/glest_game/game/script_manager.cpp +++ b/source/glest_game/game/script_manager.cpp @@ -44,9 +44,7 @@ public: } }; -ScriptManagerMessage::ScriptManagerMessage() { - this->text= ""; - this->header= ""; +ScriptManagerMessage::ScriptManagerMessage() : text(""), header("") { this->factionIndex=-1; this->teamIndex=-1; } diff --git a/source/glest_game/menu/menu_state_mods.cpp b/source/glest_game/menu/menu_state_mods.cpp index 74595a6c..ffb34f18 100644 --- a/source/glest_game/menu/menu_state_mods.cpp +++ b/source/glest_game/menu/menu_state_mods.cpp @@ -802,43 +802,6 @@ void MenuStateMods::simpleTask(BaseThread *callingThread) { } MapInfo MenuStateMods::loadMapInfo(string file) { - - -/* - Lang &lang= Lang::getInstance(); - - MapInfo mapInfo; - //memset(&mapInfo,0,sizeof(mapInfo)); - try{ -#ifdef WIN32 - FILE *f= _wfopen(utf8_decode(file).c_str(), L"rb"); -#else - FILE *f= fopen(file.c_str(), "rb"); -#endif - if(f != NULL) { - - MapFileHeader header; - size_t readBytes = fread(&header, sizeof(MapFileHeader), 1, f); - - mapInfo.size.x= header.width; - mapInfo.size.y= header.height; - mapInfo.players= header.maxFactions; - - mapInfo.desc= lang.get("MaxPlayers")+": "+intToStr(mapInfo.players)+"\n"; - mapInfo.desc+=lang.get("Size")+": "+intToStr(mapInfo.size.x) + " x " + intToStr(mapInfo.size.y); - - fclose(f); - } - } - catch(exception &e) { - SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s] loading map [%s]\n",__FILE__,__FUNCTION__,__LINE__,e.what(),file.c_str()); - throw megaglest_runtime_error("Error loading map file: [" + file + "] msg: " + e.what()); - } - - return mapInfo; -*/ - - //memset(&mapInfo,0,sizeof(mapInfo)); try{ Lang &lang= Lang::getInstance(); // Not painting properly so this is on hold diff --git a/source/glest_game/network/network_interface.cpp b/source/glest_game/network/network_interface.cpp index 8ac48557..ef636816 100644 --- a/source/glest_game/network/network_interface.cpp +++ b/source/glest_game/network/network_interface.cpp @@ -247,9 +247,7 @@ void GameNetworkInterface::requestCommand(const NetworkCommand *networkCommand, const int32 SEND_FILE = 0x20; const int32 ACK = 0x47; -FileTransferSocketThread::FileTransferSocketThread(FileTransferInfo fileInfo) -{ - this->info = fileInfo; +FileTransferSocketThread::FileTransferSocketThread(FileTransferInfo fileInfo) : info(fileInfo) { this->info.serverPort += 100; } diff --git a/source/glest_game/type_instances/command.cpp b/source/glest_game/type_instances/command.cpp index 7041d78c..4cdbb81a 100644 --- a/source/glest_game/type_instances/command.cpp +++ b/source/glest_game/type_instances/command.cpp @@ -26,22 +26,20 @@ namespace Glest{ namespace Game{ // ===================================================== // class Command // ===================================================== -Command::Command() { +Command::Command() : unitRef() { this->commandType= NULL; - this->unitRef= NULL; unitType= NULL; stateType = cst_None; stateValue = -1; unitCommandGroupId = -1; } -Command::Command(const CommandType *ct, const Vec2i &pos){ +Command::Command(const CommandType *ct, const Vec2i &pos) :unitRef() { //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] ct = [%p]\n",__FILE__,__FUNCTION__,__LINE__,ct); this->commandType= ct; this->pos= pos; this->originalPos = this->pos; - this->unitRef= NULL; unitType= NULL; stateType = cst_None; stateValue = -1; @@ -63,11 +61,10 @@ Command::Command(const CommandType *ct, Unit* unit) { unitCommandGroupId = -1; } -Command::Command(const CommandType *ct, const Vec2i &pos, const UnitType *unitType, CardinalDir facing) { +Command::Command(const CommandType *ct, const Vec2i &pos, const UnitType *unitType, CardinalDir facing) : unitRef() { this->commandType= ct; this->pos= pos; this->originalPos = this->pos; - this->unitRef= NULL; this->unitType= unitType; this->facing = facing; stateType = cst_None; diff --git a/source/glest_game/world/map.cpp b/source/glest_game/world/map.cpp index 972fb21c..ae77a9c4 100644 --- a/source/glest_game/world/map.cpp +++ b/source/glest_game/world/map.cpp @@ -403,7 +403,19 @@ Checksum Map::load(const string &path, TechTree *techTree, Tileset *tileset) { for(int i=0; i < maxPlayers; ++i) { int x=0, y=0; readBytes = fread(&x, sizeof(int32), 1, f); + if(readBytes != 1) { + char szBuf[8096]=""; + snprintf(szBuf,8096,"fread returned wrong size = %lu on line: %d.",readBytes,__LINE__); + throw megaglest_runtime_error(szBuf); + } + readBytes = fread(&y, sizeof(int32), 1, f); + if(readBytes != 1) { + char szBuf[8096]=""; + snprintf(szBuf,8096,"fread returned wrong size = %lu on line: %d.",readBytes,__LINE__); + throw megaglest_runtime_error(szBuf); + } + startLocations[i]= Vec2i(x, y)*cellScale; } @@ -416,6 +428,12 @@ Checksum Map::load(const string &path, TechTree *techTree, Tileset *tileset) { for(int i = 0; i < surfaceW; ++i) { float32 alt=0; readBytes = fread(&alt, sizeof(float32), 1, f); + if(readBytes != 1) { + char szBuf[8096]=""; + snprintf(szBuf,8096,"fread returned wrong size = %lu on line: %d.",readBytes,__LINE__); + throw megaglest_runtime_error(szBuf); + } + SurfaceCell *sc= getSurfaceCell(i, j); sc->setVertex(Vec3f(i*mapScale, alt / heightFactor, j*mapScale)); } @@ -426,6 +444,12 @@ Checksum Map::load(const string &path, TechTree *techTree, Tileset *tileset) { for(int i = 0; i < surfaceW; ++i) { int8 surf=0; readBytes = fread(&surf, sizeof(int8), 1, f); + if(readBytes != 1) { + char szBuf[8096]=""; + snprintf(szBuf,8096,"fread returned wrong size = %lu on line: %d.",readBytes,__LINE__); + throw megaglest_runtime_error(szBuf); + } + getSurfaceCell(i, j)->setSurfaceType(surf-1); } } @@ -436,6 +460,12 @@ Checksum Map::load(const string &path, TechTree *techTree, Tileset *tileset) { int8 objNumber=0; readBytes = fread(&objNumber, sizeof(int8), 1, f); + if(readBytes != 1) { + char szBuf[8096]=""; + snprintf(szBuf,8096,"fread returned wrong size = %lu on line: %d.",readBytes,__LINE__); + throw megaglest_runtime_error(szBuf); + } + SurfaceCell *sc= getSurfaceCell(toSurfCoords(Vec2i(i, j))); if(objNumber == 0) { sc->setObject(NULL); diff --git a/source/shared_lib/sources/feathery_ftp/ftpRuntime.c b/source/shared_lib/sources/feathery_ftp/ftpRuntime.c index 5c1945ad..ca2bd663 100644 --- a/source/shared_lib/sources/feathery_ftp/ftpRuntime.c +++ b/source/shared_lib/sources/feathery_ftp/ftpRuntime.c @@ -147,11 +147,11 @@ int ftpExecute(void) int socksRdy=0; ftpSession_S *pSession=NULL; int sessionId=0; - int activeJobs=0; + //int activeJobs=0; int len; int bufLen; - activeJobs = ftpGetActiveTransCnt(); // are there any active transmitions? + int activeJobs = ftpGetActiveTransCnt(); // are there any active transmitions? //for(n = 0; (activeJobs > 0) && (n < MAX_CONNECTIONS); n++) for(n = 0; n < MAX_CONNECTIONS; n++) { diff --git a/source/shared_lib/sources/graphics/model.cpp b/source/shared_lib/sources/graphics/model.cpp index 092aedce..bc9ed496 100644 --- a/source/shared_lib/sources/graphics/model.cpp +++ b/source/shared_lib/sources/graphics/model.cpp @@ -251,6 +251,11 @@ void Mesh::loadV2(int meshIndex, const string &dir, FILE *f, TextureManager *tex //read header MeshHeaderV2 meshHeader; size_t readBytes = fread(&meshHeader, sizeof(MeshHeaderV2), 1, f); + if(readBytes != 1) { + char szBuf[8096]=""; + snprintf(szBuf,8096,"fread returned wrong size = %lu on line: %d.",readBytes,__LINE__); + throw megaglest_runtime_error(szBuf); + } if(meshHeader.normalFrameCount != meshHeader.vertexFrameCount) { @@ -324,14 +329,48 @@ void Mesh::loadV2(int meshIndex, const string &dir, FILE *f, TextureManager *tex //read data readBytes = fread(vertices, sizeof(Vec3f)*frameCount*vertexCount, 1, f); + if(readBytes != 1 && (frameCount * vertexCount) != 0) { + char szBuf[8096]=""; + snprintf(szBuf,8096,"fread returned wrong size = %lu [%u][%u] on line: %d.",readBytes,frameCount,vertexCount,__LINE__); + throw megaglest_runtime_error(szBuf); + } + readBytes = fread(normals, sizeof(Vec3f)*frameCount*vertexCount, 1, f); - if(textures[mtDiffuse]!=NULL){ + if(readBytes != 1 && (frameCount * vertexCount) != 0) { + char szBuf[8096]=""; + snprintf(szBuf,8096,"fread returned wrong size = %lu [%u][%u] on line: %d.",readBytes,frameCount,vertexCount,__LINE__); + throw megaglest_runtime_error(szBuf); + } + + if(textures[mtDiffuse] != NULL) { readBytes = fread(texCoords, sizeof(Vec2f)*vertexCount, 1, f); + if(readBytes != 1 && vertexCount != 0) { + char szBuf[8096]=""; + snprintf(szBuf,8096,"fread returned wrong size = %lu [%u][%u] on line: %d.",readBytes,frameCount,vertexCount,__LINE__); + throw megaglest_runtime_error(szBuf); + } } readBytes = fread(&diffuseColor, sizeof(Vec3f), 1, f); + if(readBytes != 1) { + char szBuf[8096]=""; + snprintf(szBuf,8096,"fread returned wrong size = %lu on line: %d.",readBytes,__LINE__); + throw megaglest_runtime_error(szBuf); + } + readBytes = fread(&opacity, sizeof(float32), 1, f); + if(readBytes != 1) { + char szBuf[8096]=""; + snprintf(szBuf,8096,"fread returned wrong size = %lu on line: %d.",readBytes,__LINE__); + throw megaglest_runtime_error(szBuf); + } + fseek(f, sizeof(Vec4f)*(meshHeader.colorFrameCount-1), SEEK_CUR); readBytes = fread(indices, sizeof(uint32)*indexCount, 1, f); + if(readBytes != 1 && indexCount != 0) { + char szBuf[8096]=""; + snprintf(szBuf,8096,"fread returned wrong size = %lu [%u] on line: %d.",readBytes,indexCount,__LINE__); + throw megaglest_runtime_error(szBuf); + } } void Mesh::loadV3(int meshIndex, const string &dir, FILE *f, @@ -343,6 +382,11 @@ void Mesh::loadV3(int meshIndex, const string &dir, FILE *f, //read header MeshHeaderV3 meshHeader; size_t readBytes = fread(&meshHeader, sizeof(MeshHeaderV3), 1, f); + if(readBytes != 1) { + char szBuf[8096]=""; + snprintf(szBuf,8096,"fread returned wrong size = %lu on line: %d.",readBytes,__LINE__); + throw megaglest_runtime_error(szBuf); + } if(meshHeader.normalFrameCount != meshHeader.vertexFrameCount) { @@ -413,16 +457,50 @@ void Mesh::loadV3(int meshIndex, const string &dir, FILE *f, //read data readBytes = fread(vertices, sizeof(Vec3f)*frameCount*vertexCount, 1, f); + if(readBytes != 1 && (frameCount * vertexCount) != 0) { + char szBuf[8096]=""; + snprintf(szBuf,8096,"fread returned wrong size = %lu [%u][%u] on line: %d.",readBytes,frameCount,vertexCount,__LINE__); + throw megaglest_runtime_error(szBuf); + } + readBytes = fread(normals, sizeof(Vec3f)*frameCount*vertexCount, 1, f); - if(textures[mtDiffuse]!=NULL){ + if(readBytes != 1 && (frameCount * vertexCount) != 0) { + char szBuf[8096]=""; + snprintf(szBuf,8096,"fread returned wrong size = %lu [%u][%u] on line: %d.",readBytes,frameCount,vertexCount,__LINE__); + throw megaglest_runtime_error(szBuf); + } + + if(textures[mtDiffuse] != NULL) { for(unsigned int i=0; i(meshHeader.name); @@ -518,6 +601,12 @@ void Mesh::load(int meshIndex, const string &dir, FILE *f, TextureManager *textu if((meshHeader.textures & flag) && textureManager != NULL) { uint8 cMapPath[mapPathSize]; readBytes = fread(cMapPath, mapPathSize, 1, f); + if(readBytes != 1 && mapPathSize != 0) { + char szBuf[8096]=""; + snprintf(szBuf,8096,"fread returned wrong size = %lu [%u] on line: %d.",readBytes,mapPathSize,__LINE__); + throw megaglest_runtime_error(szBuf); + } + string mapPath= toLower(reinterpret_cast(cMapPath)); if(SystemFlags::VERBOSE_MODE_ENABLED) printf("mapPath [%s] meshHeader.textures = %d flag = %d (meshHeader.textures & flag) = %d meshIndex = %d i = %d\n",mapPath.c_str(),meshHeader.textures,flag,(meshHeader.textures & flag),meshIndex,i); @@ -537,11 +626,35 @@ void Mesh::load(int meshIndex, const string &dir, FILE *f, TextureManager *textu //read data readBytes = fread(vertices, sizeof(Vec3f)*frameCount*vertexCount, 1, f); + if(readBytes != 1 && (frameCount * vertexCount) != 0) { + char szBuf[8096]=""; + snprintf(szBuf,8096,"fread returned wrong size = %lu [%u][%u] on line: %d.",readBytes,frameCount,vertexCount,__LINE__); + throw megaglest_runtime_error(szBuf); + } + readBytes = fread(normals, sizeof(Vec3f)*frameCount*vertexCount, 1, f); + if(readBytes != 1 && (frameCount * vertexCount) != 0) { + char szBuf[8096]=""; + snprintf(szBuf,8096,"fread returned wrong size = %lu [%u][%u] on line: %d.",readBytes,frameCount,vertexCount,__LINE__); + throw megaglest_runtime_error(szBuf); + } + if(meshHeader.textures!=0){ readBytes = fread(texCoords, sizeof(Vec2f)*vertexCount, 1, f); + if(readBytes != 1 && vertexCount != 0) { + char szBuf[8096]=""; + snprintf(szBuf,8096,"fread returned wrong size = %lu [%u][%u] on line: %d.",readBytes,frameCount,vertexCount,__LINE__); + throw megaglest_runtime_error(szBuf); + } + } readBytes = fread(indices, sizeof(uint32)*indexCount, 1, f); + if(readBytes != 1 && indexCount != 0) { + char szBuf[8096]=""; + snprintf(szBuf,8096,"fread returned wrong size = %lu [%u] on line: %d.",readBytes,indexCount,__LINE__); + throw megaglest_runtime_error(szBuf); + } + //tangents if(textures[mtNormal]!=NULL){ @@ -878,6 +991,13 @@ void Model::loadG3d(const string &path, bool deletePixMapAfterLoad, //file header FileHeader fileHeader; size_t readBytes = fread(&fileHeader, sizeof(FileHeader), 1, f); + if(readBytes != 1) { + fclose(f); + char szBuf[8096]=""; + snprintf(szBuf,8096,"fread returned wrong size = %lu on line: %d.",readBytes,__LINE__); + throw megaglest_runtime_error(szBuf); + } + if(strncmp(reinterpret_cast(fileHeader.id), "G3D", 3) != 0) { fclose(f); f = NULL; @@ -893,6 +1013,12 @@ void Model::loadG3d(const string &path, bool deletePixMapAfterLoad, //model header ModelHeader modelHeader; readBytes = fread(&modelHeader, sizeof(ModelHeader), 1, f); + if(readBytes != 1) { + char szBuf[8096]=""; + snprintf(szBuf,8096,"fread returned wrong size = %lu on line: %d.",readBytes,__LINE__); + throw megaglest_runtime_error(szBuf); + } + meshCount= modelHeader.meshCount; if(SystemFlags::VERBOSE_MODE_ENABLED) printf("meshCount = %d\n",meshCount); @@ -920,6 +1046,12 @@ void Model::loadG3d(const string &path, bool deletePixMapAfterLoad, //version 3 else if(fileHeader.version == 3) { readBytes = fread(&meshCount, sizeof(meshCount), 1, f); + if(readBytes != 1 && meshCount != 0) { + char szBuf[8096]=""; + snprintf(szBuf,8096,"fread returned wrong size = %lu [%u] on line: %d.",readBytes,meshCount,__LINE__); + throw megaglest_runtime_error(szBuf); + } + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("meshCount = %d\n",meshCount); @@ -941,6 +1073,12 @@ void Model::loadG3d(const string &path, bool deletePixMapAfterLoad, //version 2 else if(fileHeader.version == 2) { readBytes = fread(&meshCount, sizeof(meshCount), 1, f); + if(readBytes != 1 && meshCount != 0) { + char szBuf[8096]=""; + snprintf(szBuf,8096,"fread returned wrong size = %lu [%u] on line: %d.",readBytes,meshCount,__LINE__); + throw megaglest_runtime_error(szBuf); + } + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("meshCount = %d\n",meshCount); diff --git a/source/shared_lib/sources/graphics/particle.cpp b/source/shared_lib/sources/graphics/particle.cpp index 68cfcdc0..d3da3c86 100644 --- a/source/shared_lib/sources/graphics/particle.cpp +++ b/source/shared_lib/sources/graphics/particle.cpp @@ -1482,14 +1482,14 @@ void ProjectileParticleSystem::update(){ //printf("Update particle targetVector [%s][%f] currentVector [%s][%f] relative = %f\n",targetVector.getString().c_str(),targetVector.length(),currentVector.getString().c_str(),currentVector.length(),relative); -#ifdef USE_STREFLOP - float absolute= clamp(streflop::fabs(static_cast(currentVector.length())), 0.0f, 1.0f); -#else - float absolute= clamp(fabs(currentVector.length()), 0.0f, 1.0f); -#endif +//#ifdef USE_STREFLOP +// float absolute= clamp(streflop::fabs(static_cast(currentVector.length())), 0.0f, 1.0f); +//#else +// float absolute= clamp(fabs(currentVector.length()), 0.0f, 1.0f); +//#endif //printf("#a currentVector.length() = %f, targetVector.length() = %f, relative = %f, absolute = %f, trajectorySpeed = %f\n",currentVector.length(),targetVector.length(),relative,absolute,trajectorySpeed); - absolute = relative; + float absolute = relative; setTween(relative,absolute); diff --git a/source/shared_lib/sources/graphics/pixmap.cpp b/source/shared_lib/sources/graphics/pixmap.cpp index 20d8677a..9b30be05 100644 --- a/source/shared_lib/sources/graphics/pixmap.cpp +++ b/source/shared_lib/sources/graphics/pixmap.cpp @@ -120,6 +120,11 @@ void PixmapIoTga::openRead(const string &path) { //read header TargaFileHeader fileHeader; size_t readBytes = fread(&fileHeader, sizeof(TargaFileHeader), 1, file); + if(readBytes != 1) { + char szBuf[8096]=""; + snprintf(szBuf,8096,"fread returned wrong size = %lu on line: %d.",readBytes,__LINE__); + throw megaglest_runtime_error(szBuf); + } //check that we can load this tga file if(fileHeader.idLength != 0) { @@ -150,6 +155,12 @@ void PixmapIoTga::read(uint8 *pixels, int components) { if(this->components == 1) { size_t readBytes = fread(&l, 1, 1, file); + if(readBytes != 1) { + char szBuf[8096]=""; + snprintf(szBuf,8096,"fread returned wrong size = %lu on line: %d.",readBytes,__LINE__); + throw megaglest_runtime_error(szBuf); + } + r= l; g= l; b= l; @@ -157,10 +168,34 @@ void PixmapIoTga::read(uint8 *pixels, int components) { } else { size_t readBytes = fread(&b, 1, 1, file); + if(readBytes != 1) { + char szBuf[8096]=""; + snprintf(szBuf,8096,"fread returned wrong size = %lu on line: %d.",readBytes,__LINE__); + throw megaglest_runtime_error(szBuf); + } + readBytes = fread(&g, 1, 1, file); + if(readBytes != 1) { + char szBuf[8096]=""; + snprintf(szBuf,8096,"fread returned wrong size = %lu on line: %d.",readBytes,__LINE__); + throw megaglest_runtime_error(szBuf); + } + readBytes = fread(&r, 1, 1, file); + if(readBytes != 1) { + char szBuf[8096]=""; + snprintf(szBuf,8096,"fread returned wrong size = %lu on line: %d.",readBytes,__LINE__); + throw megaglest_runtime_error(szBuf); + } + if(this->components == 4) { readBytes = fread(&a, 1, 1, file); + if(readBytes != 1) { + char szBuf[8096]=""; + snprintf(szBuf,8096,"fread returned wrong size = %lu on line: %d.",readBytes,__LINE__); + throw megaglest_runtime_error(szBuf); + } + } else { a= 255; @@ -256,6 +291,12 @@ void PixmapIoBmp::openRead(const string &path){ //read file header BitmapFileHeader fileHeader; size_t readBytes = fread(&fileHeader, sizeof(BitmapFileHeader), 1, file); + if(readBytes != 1) { + char szBuf[8096]=""; + snprintf(szBuf,8096,"fread returned wrong size = %lu on line: %d.",readBytes,__LINE__); + throw megaglest_runtime_error(szBuf); + } + if(fileHeader.type1!='B' || fileHeader.type2!='M'){ throw megaglest_runtime_error(path +" is not a bitmap"); } @@ -263,6 +304,12 @@ void PixmapIoBmp::openRead(const string &path){ //read info header BitmapInfoHeader infoHeader; readBytes = fread(&infoHeader, sizeof(BitmapInfoHeader), 1, file); + if(readBytes != 1) { + char szBuf[8096]=""; + snprintf(szBuf,8096,"fread returned wrong size = %lu on line: %d.",readBytes,__LINE__); + throw megaglest_runtime_error(szBuf); + } + if(infoHeader.bitCount!=24){ throw megaglest_runtime_error(path+" is not a 24 bit bitmap"); } @@ -280,8 +327,26 @@ void PixmapIoBmp::read(uint8 *pixels, int components) { for(int i=0; i