diff options
author | Spp <none@none> | 2010-08-31 10:23:22 +0200 |
---|---|---|
committer | Spp <none@none> | 2010-08-31 10:23:22 +0200 |
commit | 849ae84f5b79f52ac60a904f98b10219a0ed7cf7 (patch) | |
tree | 2db022e1137d2b6a68a42122808472ded3e8c313 | |
parent | e252b8abe764e5e348e8ec89deec944729437147 (diff) |
Core: Fix more warnings and fix compile under linux 64
--HG--
branch : trunk
-rw-r--r-- | src/genrevision/genrevision.cpp | 128 | ||||
-rw-r--r-- | src/server/collision/Maps/MapTree.cpp | 54 | ||||
-rw-r--r-- | src/server/game/Entities/Object/Object.cpp | 2 | ||||
-rw-r--r-- | src/server/game/Maps/Map.cpp | 73 | ||||
-rw-r--r-- | src/server/worldserver/TCSoap/TCSoap.cpp | 2 |
5 files changed, 137 insertions, 122 deletions
diff --git a/src/genrevision/genrevision.cpp b/src/genrevision/genrevision.cpp index eb868248124..6d5a4451296 100644 --- a/src/genrevision/genrevision.cpp +++ b/src/genrevision/genrevision.cpp @@ -34,28 +34,37 @@ struct RawData char time_str[200]; }; -void extractDataFromSvn(FILE* EntriesFile, bool url, RawData& data) +bool extractDataFromSvn(std::string filename, bool url, RawData& data) { - char buf[200]; + FILE* EntriesFile = fopen(filename.c_str(), "r"); + if (!EntriesFile) + return false; + char aux[800]; + char buf[200]; char repo_str[200]; char num_str[200]; + bool ret = false; - fgets(buf,200,EntriesFile); - fgets(buf,200,EntriesFile); - fgets(buf,200,EntriesFile); - fgets(buf,200,EntriesFile); sscanf(buf,"%s",num_str); - fgets(buf,200,EntriesFile); sscanf(buf,"%s",repo_str); - fgets(buf,200,EntriesFile); - fgets(buf,200,EntriesFile); - fgets(buf,200,EntriesFile); - fgets(buf,200,EntriesFile); - fgets(buf,200,EntriesFile); sscanf(buf,"%10sT%8s",data.date_str,data.time_str); - - if(url) - sprintf(data.rev_str,"%s at %s",num_str,repo_str); - else - strcpy(data.rev_str,num_str); + if (fgets(aux, 600, EntriesFile) && fgets(buf, 200, EntriesFile)) + { + sscanf(buf, "%s", num_str); + if (fgets(buf, 200, EntriesFile)) + { + sscanf(buf, "%s", repo_str); + if (fgets(aux, 800, EntriesFile) && fgets(buf, 200, EntriesFile)) + { + sscanf(buf, "%10sT%8s", data.date_str, data.time_str); + if (url) + sprintf(data.rev_str,"%s at %s",num_str,repo_str); + else + strcpy(data.rev_str,num_str); + ret = true; + } + } + } + fclose(EntriesFile); + return ret; } void extractDataFromHG(FILE* EntriesFile, std::string /*path*/, bool /*url*/, RawData& data) @@ -66,16 +75,16 @@ void extractDataFromHG(FILE* EntriesFile, std::string /*path*/, bool /*url*/, Ra char revision_str[200]; bool found = false; - while(fgets(buf,200,EntriesFile)) + while (fgets(buf,200,EntriesFile)) { - if(sscanf(buf,"%s %s",hash_str,revision_str)==2) + if (sscanf(buf,"%s %s",hash_str,revision_str)==2) { found = true; break; } } - if(!found) + if (!found) { strcpy(data.hash_str,"*"); strcpy(data.rev_str,"*"); @@ -106,17 +115,19 @@ void extractDataFromArchive(FILE* EntriesFile, std::string /*path*/, bool /*url* char revision_str[200]; bool found = false; - fgets(buf,200,EntriesFile); - while(fgets(buf,200,EntriesFile)) + if (fgets(buf,200,EntriesFile)) { - if(sscanf(buf,"%s %s",revision_str,hash_str)==2) + while (fgets(buf,200,EntriesFile)) { - found = true; - break; + if (sscanf(buf,"%s %s",revision_str,hash_str)==2) + { + found = true; + break; + } } } - if(!found) + if (!found) { strcpy(data.hash_str,"*"); strcpy(data.rev_str,"*"); @@ -148,16 +159,16 @@ void extractDataFromGit(FILE* EntriesFile, std::string path, bool url, RawData& char url_str[200]; bool found = false; - while(fgets(buf,200,EntriesFile)) + while (fgets(buf,200,EntriesFile)) { - if(sscanf(buf,"%s\t\tbranch %s of %s",hash_str,branch_str,url_str)==3) + if (sscanf(buf,"%s\t\tbranch %s of %s",hash_str,branch_str,url_str)==3) { found = true; break; } } - if(!found) + if (!found) { strcpy(data.hash_str,"*"); strcpy(data.rev_str,"*"); @@ -166,7 +177,7 @@ void extractDataFromGit(FILE* EntriesFile, std::string path, bool url, RawData& return; } - if(url) + if (url) { char* host_str = NULL; char* acc_str = NULL; @@ -175,7 +186,7 @@ void extractDataFromGit(FILE* EntriesFile, std::string path, bool url, RawData& // parse URL like git@github.com:mangos/mangos char url_buf[200]; int res = sscanf(url_str,"git@%s",url_buf); - if(res) + if (res) { host_str = strtok(url_buf,":"); acc_str = strtok(NULL,"/"); @@ -184,7 +195,7 @@ void extractDataFromGit(FILE* EntriesFile, std::string path, bool url, RawData& else { res = sscanf(url_str,"git://%s",url_buf); - if(res) + if (res) { host_str = strtok(url_buf,"/"); acc_str = strtok(NULL,"/"); @@ -193,7 +204,7 @@ void extractDataFromGit(FILE* EntriesFile, std::string path, bool url, RawData& } // can generate nice link - if(res) + if (res) sprintf(data.rev_str,"http://%s/%s/%s/commit/%s",host_str,acc_str,repo_str,hash_str); // unknonw URL format, use as-is else @@ -207,18 +218,18 @@ void extractDataFromGit(FILE* EntriesFile, std::string path, bool url, RawData& time_t rev_time = 0; // extracting date/time FILE* LogFile = fopen((path+".git/logs/HEAD").c_str(), "r"); - if(LogFile) + if (LogFile) { - while(fgets(buf,200,LogFile)) + while (fgets(buf,200,LogFile)) { char buf2[200]; char new_hash[200]; int unix_time = 0; int res2 = sscanf(buf,"%s %s %s %s %i",buf2,new_hash,buf2,buf2,&unix_time); - if(res2!=5) + if (res2!=5) continue; - if(strcmp(hash_str,new_hash)) + if (strcmp(hash_str,new_hash)) continue; rev_time = unix_time; @@ -227,7 +238,7 @@ void extractDataFromGit(FILE* EntriesFile, std::string path, bool url, RawData& fclose(LogFile); - if(rev_time) + if (rev_time) { tm* aTm = localtime(&rev_time); // YYYY year @@ -252,21 +263,10 @@ void extractDataFromGit(FILE* EntriesFile, std::string path, bool url, RawData& } } -bool extractDataFromSvn(std::string filename, bool url, RawData& data) -{ - FILE* EntriesFile = fopen(filename.c_str(), "r"); - if(!EntriesFile) - return false; - - extractDataFromSvn(EntriesFile,url,data); - fclose(EntriesFile); - return true; -} - bool extractDataFromGit(std::string filename, std::string path, bool url, RawData& data) { FILE* EntriesFile = fopen(filename.c_str(), "r"); - if(!EntriesFile) + if (!EntriesFile) return false; extractDataFromGit(EntriesFile,path,url,data); @@ -277,7 +277,7 @@ bool extractDataFromGit(std::string filename, std::string path, bool url, RawDat bool extractDataFromHG(std::string filename, std::string path, bool url, RawData& data) { FILE* EntriesFile = fopen(filename.c_str(), "r"); - if(!EntriesFile) + if (!EntriesFile) return false; extractDataFromHG(EntriesFile,path,url,data); @@ -288,7 +288,7 @@ bool extractDataFromHG(std::string filename, std::string path, bool url, RawData bool extractDataFromArchive(std::string filename, std::string path, bool url, RawData& data) { FILE* EntriesFile = fopen(filename.c_str(), "r"); - if(!EntriesFile) + if (!EntriesFile) return false; extractDataFromArchive(EntriesFile,path,url,data); @@ -340,13 +340,13 @@ int main(int argc, char **argv) // -m build mode string for (int k = 1; k <= argc; ++k) { - if(!argv[k] || !*argv[k]) + if (!argv[k] || !*argv[k]) break; - if(argv[k][0]!='-') + if (argv[k][0]!='-') { path = argv[k]; - if(path.size() > 0 && (path[path.size()-1]!='/' || path[path.size()-1]!='\\')) + if (path.size() > 0 && (path[path.size()-1]!='/' || path[path.size()-1]!='\\')) path += '/'; break; } @@ -391,7 +391,7 @@ int main(int argc, char **argv) bool res = false; - if(svn_prefered) + if (svn_prefered) { /// SVN data res = extractDataFromSvn(path+".svn/entries",use_url,data); @@ -417,7 +417,7 @@ int main(int argc, char **argv) if (!res) res = extractDataFromArchive(path+"_hg_archival.txt",path,use_url,data); } - else if(git_prefered) + else if (git_prefered) { // GIT data res = extractDataFromGit(path+".git/FETCH_HEAD",path,use_url,data); @@ -445,7 +445,7 @@ int main(int argc, char **argv) } - else if(hg_prefered) + else if (hg_prefered) { // HG data res = extractDataFromHG(path+".hg/branchheads.cache",path,use_url,data); @@ -472,7 +472,7 @@ int main(int argc, char **argv) res = extractDataFromArchive(path+"_hg_archival.txt",path,use_url,data); } - if(res) + if (res) newData = generateHeader(data.rev_str,data.date_str,data.time_str,data.hash_str); else newData = generateHeader("*", "*", "*", "*"); @@ -481,12 +481,12 @@ int main(int argc, char **argv) /// get existed header data for compare std::string oldData; - if(FILE* HeaderFile = fopen("revision.h","rb")) + if (FILE* HeaderFile = fopen("revision.h","rb")) { - while(!feof(HeaderFile)) + while (!feof(HeaderFile)) { int c = fgetc(HeaderFile); - if(c < 0) + if (c < 0) break; oldData += (char)c; } @@ -495,9 +495,9 @@ int main(int argc, char **argv) } /// update header only if different data - if(newData != oldData) + if (newData != oldData) { - if(FILE* OutputFile = fopen("revision.h","wb")) + if (FILE* OutputFile = fopen("revision.h","wb")) { fprintf(OutputFile,"%s",newData.c_str()); fclose(OutputFile); diff --git a/src/server/collision/Maps/MapTree.cpp b/src/server/collision/Maps/MapTree.cpp index 79ec106a27a..c59f78d1f6b 100644 --- a/src/server/collision/Maps/MapTree.cpp +++ b/src/server/collision/Maps/MapTree.cpp @@ -388,29 +388,33 @@ namespace VMAP // update tree uint32 referencedVal; - fread(&referencedVal, sizeof(uint32), 1, tf); - if (!iLoadedSpawns.count(referencedVal)) + if (fread(&referencedVal, sizeof(uint32), 1, tf) == 1) { -#ifdef VMAP_DEBUG - if (referencedVal > iNTreeValues) + if (!iLoadedSpawns.count(referencedVal)) { - sLog.outDebug("StaticMapTree::LoadMapTile() : invalid tree element (%u/%u)", referencedVal, iNTreeValues); - continue; - } +#ifdef VMAP_DEBUG + if (referencedVal > iNTreeValues) + { + sLog.outDebug("StaticMapTree::LoadMapTile() : invalid tree element (%u/%u)", referencedVal, iNTreeValues); + continue; + } #endif - iTreeValues[referencedVal] = ModelInstance(spawn, model); - iLoadedSpawns[referencedVal] = 1; - } - else - { - ++iLoadedSpawns[referencedVal]; + iTreeValues[referencedVal] = ModelInstance(spawn, model); + iLoadedSpawns[referencedVal] = 1; + } + else + { + ++iLoadedSpawns[referencedVal]; #ifdef VMAP_DEBUG - if (iTreeValues[referencedVal].ID != spawn.ID) - sLog.outDebug("StaticMapTree::LoadMapTile() : trying to load wrong spawn in node"); - else if (iTreeValues[referencedVal].name != spawn.name) - sLog.outDebug("StaticMapTree::LoadMapTile() : name collision on GUID=%u", spawn.ID); + if (iTreeValues[referencedVal].ID != spawn.ID) + sLog.outDebug("StaticMapTree::LoadMapTile() : trying to load wrong spawn in node"); + else if (iTreeValues[referencedVal].name != spawn.name) + sLog.outDebug("StaticMapTree::LoadMapTile() : name collision on GUID=%u", spawn.ID); #endif + } } + else + result = false; } } iLoadedTiles[packTileID(tileX, tileY)] = true; @@ -458,15 +462,17 @@ namespace VMAP // update tree uint32 referencedNode; - fread(&referencedNode, sizeof(uint32), 1, tf); - if (!iLoadedSpawns.count(referencedNode)) + if (fread(&referencedNode, sizeof(uint32), 1, tf) != 1) + result = false; + else { + if (!iLoadedSpawns.count(referencedNode)) sLog.outError("StaticMapTree::UnloadMapTile() : trying to unload non-referenced model '%s' (ID:%u)", spawn.name.c_str(), spawn.ID); - } - else if (--iLoadedSpawns[referencedNode] == 0) - { - iTreeValues[referencedNode].setUnloaded(); - iLoadedSpawns.erase(referencedNode); + else if (--iLoadedSpawns[referencedNode] == 0) + { + iTreeValues[referencedNode].setUnloaded(); + iLoadedSpawns.erase(referencedNode); + } } } } diff --git a/src/server/game/Entities/Object/Object.cpp b/src/server/game/Entities/Object/Object.cpp index 271a523a611..0099c778289 100644 --- a/src/server/game/Entities/Object/Object.cpp +++ b/src/server/game/Entities/Object/Object.cpp @@ -1188,7 +1188,7 @@ void MovementInfo::OutDebug() sLog.outString("guid " UI64FMTD, guid); sLog.outString("flags %u", flags); sLog.outString("flags2 %u", flags2); - sLog.outString("time %u current time %u", flags2, ::time(NULL)); + sLog.outString("time %u current time " UI64FMTD "", flags2, uint64(::time(NULL))); sLog.outString("position: `%s`", pos.ToString().c_str()); if (flags & MOVEMENTFLAG_ONTRANSPORT) { diff --git a/src/server/game/Maps/Map.cpp b/src/server/game/Maps/Map.cpp index aa6b348e4c9..2986c270b1a 100644 --- a/src/server/game/Maps/Map.cpp +++ b/src/server/game/Maps/Map.cpp @@ -85,28 +85,25 @@ bool Map::ExistMap(uint32 mapid,int gx,int gy) char* tmp = new char[len]; snprintf(tmp, len, (char *)(sWorld.GetDataPath()+"maps/%03u%02u%02u.map").c_str(),mapid,gx,gy); + bool ret = false; FILE *pf=fopen(tmp,"rb"); if (!pf) - { sLog.outError("Map file '%s': does not exist!",tmp); - delete[] tmp; - return false; - } - - map_fileheader header; - fread(&header, sizeof(header), 1, pf); - if (header.mapMagic != uint32(MAP_MAGIC) || header.versionMagic != uint32(MAP_VERSION_MAGIC)) + else { - sLog.outError("Map file '%s' is from an incompatible clientversion. Please recreate using the mapextractor.",tmp); - delete [] tmp; - fclose(pf); //close file before return - return false; + map_fileheader header; + if (fread(&header, sizeof(header), 1, pf) == 1) + { + if (header.mapMagic != uint32(MAP_MAGIC) || header.versionMagic != uint32(MAP_VERSION_MAGIC)) + sLog.outError("Map file '%s' is from an incompatible clientversion. Please recreate using the mapextractor.",tmp); + else + ret = true; + } } - delete [] tmp; - fclose(pf); - return true; + fclose(pf); //close file before return + return ret; } bool Map::ExistVMap(uint32 mapid,int gx,int gy) @@ -1109,7 +1106,13 @@ bool GridMap::loadData(char *filename) FILE *in = fopen(filename, "rb"); if (!in) return true; - fread(&header, sizeof(header),1,in); + + if (fread(&header, sizeof(header),1,in) != 1) + { + fclose(in); + return false; + } + if (header.mapMagic == uint32(MAP_MAGIC) && header.versionMagic == uint32(MAP_VERSION_MAGIC)) { // loadup area data @@ -1160,25 +1163,26 @@ bool GridMap::loadAreaData(FILE *in, uint32 offset, uint32 /*size*/) { map_areaHeader header; fseek(in, offset, SEEK_SET); - fread(&header, sizeof(header), 1, in); - if (header.fourcc != uint32(MAP_AREA_MAGIC)) + + if (fread(&header, sizeof(header), 1, in) != 1 || header.fourcc != uint32(MAP_AREA_MAGIC)) return false; m_gridArea = header.gridArea; if (!(header.flags & MAP_AREA_NO_AREA)) { m_area_map = new uint16 [16*16]; - fread(m_area_map, sizeof(uint16), 16*16, in); + if (fread(m_area_map, sizeof(uint16), 16*16, in) != 16*16) + return false; } return true; } -bool GridMap::loadHeihgtData(FILE *in, uint32 offset, uint32 /*size*/) +bool GridMap::loadHeihgtData(FILE *in, uint32 offset, uint32 /*size*/) { map_heightHeader header; fseek(in, offset, SEEK_SET); - fread(&header, sizeof(header), 1, in); - if (header.fourcc != uint32(MAP_HEIGHT_MAGIC)) + + if (fread(&header, sizeof(header), 1, in) != 1 || header.fourcc != uint32(MAP_HEIGHT_MAGIC)) return false; m_gridHeight = header.gridHeight; @@ -1188,8 +1192,9 @@ bool GridMap::loadHeihgtData(FILE *in, uint32 offset, uint32 /*size*/) { m_uint16_V9 = new uint16 [129*129]; m_uint16_V8 = new uint16 [128*128]; - fread(m_uint16_V9, sizeof(uint16), 129*129, in); - fread(m_uint16_V8, sizeof(uint16), 128*128, in); + if (fread(m_uint16_V9, sizeof(uint16), 129*129, in) != 129*129 || + fread(m_uint16_V8, sizeof(uint16), 128*128, in) != 128*128) + return false; m_gridIntHeightMultiplier = (header.gridMaxHeight - header.gridHeight) / 65535; m_gridGetHeight = &GridMap::getHeightFromUint16; } @@ -1197,8 +1202,9 @@ bool GridMap::loadHeihgtData(FILE *in, uint32 offset, uint32 /*size*/) { m_uint8_V9 = new uint8 [129*129]; m_uint8_V8 = new uint8 [128*128]; - fread(m_uint8_V9, sizeof(uint8), 129*129, in); - fread(m_uint8_V8, sizeof(uint8), 128*128, in); + if (fread(m_uint8_V9, sizeof(uint8), 129*129, in) != 129*129 || + fread(m_uint8_V8, sizeof(uint8), 128*128, in) != 128*128) + return false; m_gridIntHeightMultiplier = (header.gridMaxHeight - header.gridHeight) / 255; m_gridGetHeight = &GridMap::getHeightFromUint8; } @@ -1206,8 +1212,9 @@ bool GridMap::loadHeihgtData(FILE *in, uint32 offset, uint32 /*size*/) { m_V9 = new float [129*129]; m_V8 = new float [128*128]; - fread(m_V9, sizeof(float), 129*129, in); - fread(m_V8, sizeof(float), 128*128, in); + if (fread(m_V9, sizeof(float), 129*129, in) != 129*129 || + fread(m_V8, sizeof(float), 128*128, in) != 128*128) + return false; m_gridGetHeight = &GridMap::getHeightFromFloat; } } @@ -1220,8 +1227,8 @@ bool GridMap::loadLiquidData(FILE *in, uint32 offset, uint32 /*size*/) { map_liquidHeader header; fseek(in, offset, SEEK_SET); - fread(&header, sizeof(header), 1, in); - if (header.fourcc != uint32(MAP_LIQUID_MAGIC)) + + if (fread(&header, sizeof(header), 1, in) != 1 || header.fourcc != uint32(MAP_LIQUID_MAGIC)) return false; m_liquidType = header.liquidType; @@ -1234,12 +1241,14 @@ bool GridMap::loadLiquidData(FILE *in, uint32 offset, uint32 /*size*/) if (!(header.flags & MAP_LIQUID_NO_TYPE)) { m_liquid_type = new uint8 [16*16]; - fread(m_liquid_type, sizeof(uint8), 16*16, in); + if (fread(m_liquid_type, sizeof(uint8), 16*16, in) != 16*16) + return false; } if (!(header.flags & MAP_LIQUID_NO_HEIGHT)) { m_liquid_map = new float [m_liquid_width*m_liquid_height]; - fread(m_liquid_map, sizeof(float), m_liquid_width*m_liquid_height, in); + if (fread(m_liquid_map, sizeof(float), m_liquid_width*m_liquid_height, in) != m_liquid_width*m_liquid_height) + return false; } return true; } diff --git a/src/server/worldserver/TCSoap/TCSoap.cpp b/src/server/worldserver/TCSoap/TCSoap.cpp index 9a862c6dd81..2a52e054acd 100644 --- a/src/server/worldserver/TCSoap/TCSoap.cpp +++ b/src/server/worldserver/TCSoap/TCSoap.cpp @@ -29,7 +29,7 @@ void TCSoapRunnable::run() pool.activate (THR_NEW_LWP | THR_JOINABLE, POOL_SIZE); struct soap soap; - SOCKET m, s; + int m, s; soap_init(&soap); soap_set_imode(&soap, SOAP_C_UTFSTRING); soap_set_omode(&soap, SOAP_C_UTFSTRING); |