- round #2 of coverity bug fixes

This commit is contained in:
SoftCoder 2013-12-14 22:37:15 -08:00
parent b8ab732b85
commit f269273f07
25 changed files with 195 additions and 152 deletions

View File

@ -14,7 +14,7 @@
#include "graphics_factory_gl.h"
#include "graphics_interface.h"
#include "config.h"
//#include <png.h>
#include "platform_common.h"
#include <memory>
using namespace Shared::Graphics;

View File

@ -195,10 +195,10 @@ TravelState PathFinder::findPath(Unit *unit, const Vec2i &finalPos, bool *wasStu
UnitPathInterface *path= unit->getPath();
if(path->isEmpty() == false) {
if(dynamic_cast<UnitPathBasic *>(path) != NULL) {
UnitPathBasic *basic_path = dynamic_cast<UnitPathBasic *>(path);
if(basic_path != NULL) {
//route cache
UnitPathBasic *basicPath = dynamic_cast<UnitPathBasic *>(path);
Vec2i pos= basicPath->pop(frameIndex < 0);
Vec2i pos= basic_path->pop(frameIndex < 0);
if(map->canMove(unit, unit->getPos(), pos)) {
if(frameIndex < 0) {

View File

@ -318,8 +318,8 @@ string getGameReadWritePath(string lookupKey) {
}
}
if(path == "" && getenv("GLESTHOME") != NULL) {
path = getenv("GLESTHOME");
if(path == "") {
path = safeCharPtrCopy(getenv("GLESTHOME"),8095);
if(path != "" && EndsWith(path, "/") == false && EndsWith(path, "\\") == false) {
path += "/";
}

View File

@ -3987,7 +3987,7 @@ void Renderer::MapRenderer::load(float coordStep) {
//printf("Total # of layers for this map = %d totalCellCount = %d overall render reduction ratio = %d times\n",layers.size(),totalCellCount,(totalCellCount / layers.size()));
}
template<typename T> void* _bindVBO(GLuint vbo,std::vector<T> buf,int target=GL_ARRAY_BUFFER_ARB) {
template<typename T> void* _bindVBO(GLuint vbo,std::vector<T> &buf,int target=GL_ARRAY_BUFFER_ARB) {
void* result = NULL;
if(vbo) {
glBindBuffer(target,vbo);
@ -4025,25 +4025,6 @@ void Renderer::MapRenderer::Layer::renderVisibleLayer() {
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glClientActiveTexture(Renderer::baseTexUnit);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
// glVertexPointer(3,GL_FLOAT,0,_bindVBO(vbo_vertices,vertices));
// glNormalPointer(GL_FLOAT,0,_bindVBO(vbo_normals,normals));
//
// glClientActiveTexture(Renderer::fowTexUnit);
// glTexCoordPointer(2,GL_FLOAT,0,_bindVBO(vbo_fowTexCoords,fowTexCoords));
//
// glClientActiveTexture(Renderer::baseTexUnit);
// glBindTexture(GL_TEXTURE_2D,textureHandle);
// glTexCoordPointer(2,GL_FLOAT,0,_bindVBO(vbo_surfTexCoords,surfTexCoords));
//
// //glDrawElements(GL_TRIANGLES,indexCount,GL_UNSIGNED_INT,_bindVBO(vbo_indices,indices,GL_ELEMENT_ARRAY_BUFFER_ARB));
// glDrawArrays(GL_TRIANGLE_STRIP, 0, vertices.size());
// //unsigned short faceIndices[4] = {0, 1, 2, 3};
// //glDrawElements(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_SHORT, &faceIndices[0]);
}
void Renderer::MapRenderer::Layer::render(VisibleQuadContainerCache &qCache) {

View File

@ -1757,7 +1757,8 @@ void MenuStateCustomGame::PlayNow(bool saveGame) {
for(unsigned int j = 0; j < languageList.size(); ++j) {
char szMsg[8096]="";
if(lang.hasString("NetworkSlotUnassignedError",languageList[j]) == true) {
strcpy(szMsg,lang.getString("NetworkSlotUnassignedError").c_str());
string msg_string = lang.getString("NetworkSlotUnassignedError");
strncpy(szMsg,msg_string.c_str(),std::min((int)msg_string.length(),8095));
}
else {
strcpy(szMsg,"Cannot start game, some player(s) are not in a network game slot!");
@ -3512,8 +3513,10 @@ void MenuStateCustomGame::loadGameSettings(GameSettings *gameSettings,bool force
gameSettings->setTeam(slotIndex, listBoxTeams[i].getSelectedItemIndex());
gameSettings->setStartLocationIndex(slotIndex, i);
if(listBoxControls[i].getSelectedItemIndex() == ctNetwork || listBoxControls[i].getSelectedItemIndex() == ctNetworkUnassigned) {
if(serverInterface->getSlot(i) != NULL &&
if(listBoxControls[i].getSelectedItemIndex() == ctNetwork ||
listBoxControls[i].getSelectedItemIndex() == ctNetworkUnassigned) {
if(serverInterface != NULL &&
serverInterface->getSlot(i) != NULL &&
serverInterface->getSlot(i)->isConnected()) {
gameSettings->setNetworkPlayerStatuses(slotIndex,serverInterface->getSlot(i)->getNetworkPlayerStatus());

View File

@ -2262,32 +2262,32 @@ bool NetworkMessageSynchNetworkGameDataStatus::receive(Socket* socket) {
if(result == true && data.header.techCRCFileCount > 0) {
fromEndianHeader();
// Here we loop possibly multiple times
int packetLoopCount = 1;
uint32 packetLoopCount = 1;
if(data.header.techCRCFileCount > (uint32)NetworkMessageSynchNetworkGameDataStatus::maxFileCRCPacketCount) {
packetLoopCount = (data.header.techCRCFileCount / NetworkMessageSynchNetworkGameDataStatus::maxFileCRCPacketCount);
if(data.header.techCRCFileCount % NetworkMessageSynchNetworkGameDataStatus::maxFileCRCPacketCount > 0) {
packetLoopCount = (data.header.techCRCFileCount / (uint32)NetworkMessageSynchNetworkGameDataStatus::maxFileCRCPacketCount);
if(data.header.techCRCFileCount % (uint32)NetworkMessageSynchNetworkGameDataStatus::maxFileCRCPacketCount > 0) {
packetLoopCount++;
}
}
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] packetLoopCount = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,packetLoopCount);
for(int iPacketLoop = 0; iPacketLoop < packetLoopCount; ++iPacketLoop) {
for(uint32 iPacketLoop = 0; iPacketLoop < packetLoopCount; ++iPacketLoop) {
int packetIndex = iPacketLoop * NetworkMessageSynchNetworkGameDataStatus::maxFileCRCPacketCount;
int maxFileCountPerPacket = maxFileCRCPacketCount;
int packetFileCount = min((uint32)maxFileCountPerPacket,data.header.techCRCFileCount - packetIndex);
uint32 packetIndex = iPacketLoop * (uint32)NetworkMessageSynchNetworkGameDataStatus::maxFileCRCPacketCount;
uint32 maxFileCountPerPacket = (uint32)maxFileCRCPacketCount;
uint32 packetFileCount = min((uint32)maxFileCountPerPacket,data.header.techCRCFileCount - packetIndex);
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] iPacketLoop = %d, packetIndex = %d, packetFileCount = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,iPacketLoop,packetIndex,packetFileCount);
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] iPacketLoop = %u, packetIndex = %u, packetFileCount = %u\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,iPacketLoop,packetIndex,packetFileCount);
result = NetworkMessage::receive(socket, &data.detail.techCRCFileList[packetIndex], (DetailSize1 * packetFileCount),true);
result = NetworkMessage::receive(socket, &data.detail.techCRCFileList[packetIndex], ((uint32)DetailSize1 * packetFileCount),true);
if(result == true) {
for(int i = 0; i < (int)data.header.techCRCFileCount; ++i) {
data.detail.techCRCFileList[i].nullTerminate();
}
// Wait a max of x seconds for this message
result = NetworkMessage::receive(socket, &data.detail.techCRCFileCRCList[packetIndex], (DetailSize2 * packetFileCount),true);
result = NetworkMessage::receive(socket, &data.detail.techCRCFileCRCList[packetIndex], ((uint32)DetailSize2 * packetFileCount),true);
}
}
fromEndianDetail();

View File

@ -450,6 +450,9 @@ std::vector<std::string> FactionType::validateFactionType() {
// exist in this faction
if(cmdType->getClass() == ccBuild) {
const BuildCommandType *build = dynamic_cast<const BuildCommandType *>(cmdType);
if(build == NULL) {
throw megaglest_runtime_error("build == NULL");
}
for(int k = 0; k < build->getBuildingCount(); ++k) {
const UnitType *buildUnit = build->getBuilding(k);

View File

@ -81,6 +81,26 @@ protected:
std::map<string,int> prodSpeedMorphIsMultiplierValueList;
public:
UpgradeTypeBase() {
maxHp = 0;;
maxHpIsMultiplier = false;
maxHpRegeneration = 0;
sight = 0;
sightIsMultiplier = false;
maxEp = 0;;
maxEpIsMultiplier = false;
maxEpRegeneration = 0;
armor = 0;
armorIsMultiplier = false;
attackStrength = 0;
attackStrengthIsMultiplier = false;
attackRange = 0;
attackRangeIsMultiplier = false;
moveSpeed = 0;
moveSpeedIsMultiplier = false;
prodSpeed = 0;
prodSpeedIsMultiplier = false;
}
virtual ~UpgradeTypeBase() {}
int getMaxHp() const {return maxHp;}

View File

@ -71,19 +71,19 @@ void Minimap::init(int w, int h, const World *world, bool fogOfWar) {
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
fowPixmap0->setPixels(&f);
fowPixmap0->setPixels(&f,1);
if((this->gameSettings->getFlagTypes1() & ft1_show_map_resources) == ft1_show_map_resources) {
f = 0.f;
fowPixmap1->setPixels(&f);
fowPixmap1->setPixels(&f,1);
f = 0.5f;
for (int y=1; y < scaledH - 1; ++y) {
for (int x=1; x < scaledW - 1; ++x) {
fowPixmap1->setPixel(x, y, &f);
fowPixmap1->setPixel(x, y, &f,1);
}
}
}
else {
fowPixmap1->setPixels(&f);
fowPixmap1->setPixels(&f,1);
}
}
@ -99,8 +99,7 @@ void Minimap::init(int w, int h, const World *world, bool fogOfWar) {
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] scaledW = %d, scaledH = %d, potW = %d, potH = %d\n",__FILE__,__FUNCTION__,__LINE__,scaledW,scaledH,potW,potH);
fowTex->getPixmap()->init(potW, potH, 1);
const float *fPtr = &f;
fowTex->getPixmap()->setPixels(fPtr);
fowTex->getPixmap()->setPixels(&f,1);
}
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
@ -269,7 +268,7 @@ void Minimap::computeTexture(const World *world) {
const Map *map= world->getMap();
if(tex) {
tex->getPixmap()->setPixels(Vec4f(1.f, 1.f, 1.f, 0.1f).ptr());
tex->getPixmap()->setPixels(Vec4f(1.f, 1.f, 1.f, 0.1f).ptr(),tex->getPixmap()->getComponents());
for(int j=0; j<tex->getPixmap()->getH(); ++j){
for(int i=0; i<tex->getPixmap()->getW(); ++i){

View File

@ -272,8 +272,8 @@ public:
float getComponentf(int x, int y, int component) const;
//set data
void setPixel(int x, int y, const uint8 *value);
void setPixel(int x, int y, const float32 *value);
void setPixel(int x, int y, const uint8 *value, int arraySize);
void setPixel(int x, int y, const float32 *value, int arraySize);
void setComponent(int x, int y, int component, uint8 value);
void setComponent(int x, int y, int component, float32 value);
@ -283,8 +283,8 @@ public:
void setPixel(int x, int y, float p);
//mass set
void setPixels(const uint8 *value);
void setPixels(const float32 *value);
void setPixels(const uint8 *value, int arraySize);
void setPixels(const float32 *value, int arraySize);
void setComponents(int component, uint8 value);
void setComponents(int component, float32 value);

View File

@ -303,6 +303,8 @@ bool valid_utf8_file(const char* file_name);
string getFileTextContents(string path);
string safeCharPtrCopy(const char *ptr, int maxLength=-1);
class ValueCheckerVault {
protected:

View File

@ -205,6 +205,7 @@ int zipfile_tool(int argc, const char *argv[]) {
if (inflateInit(&stream)) {
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("inflateInit() failed!\n");
if(pInfile) fclose(pInfile);
return EXIT_FAILURE;
}
@ -243,6 +244,7 @@ int zipfile_tool(int argc, const char *argv[]) {
}
else if (status != Z_OK) {
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("inflate() failed with status %i!\n", status);
if(pOutfile) fclose(pOutfile);
return EXIT_FAILURE;
}
}

View File

@ -35,9 +35,9 @@
*/
typedef struct
{
char name[MAXLEN_USERNAME]; ///< user name
char passw[MAXLEN_PASSWORD]; ///< password of the account
char ftpRoot[MAX_PATH_LEN]; ///< root path of the user account on the server
char name[MAXLEN_USERNAME+1]; ///< user name
char passw[MAXLEN_PASSWORD+1]; ///< password of the account
char ftpRoot[MAX_PATH_LEN+1]; ///< root path of the user account on the server
int ftpRootLen; ///< length of ftpRoot
int accRights; ///< access rights of a account

View File

@ -257,7 +257,8 @@ const char* ftpGetRealPath(int id, const char* path, int normalize)
int ftpRootLen;
int len;
strcpy(ftpRoot,ftpGetRoot(sessions[id].userId, &len));
const char *ftp_rootget = ftpGetRoot(sessions[id].userId, &len);
snprintf(ftpRoot,2047,"%s",ftp_rootget);
ftpRootLen = strlen(ftpRoot);
if(ftpRootLen > 0 && ftpRoot[ftpRootLen-1] != '/') {
strcat(ftpRoot,"/");
@ -313,7 +314,7 @@ if(VERBOSE_MODE_ENABLED) printf("ftpChangeDir path [%s] realPath [%s] sessions[i
if(ftpStat(realPath, &fileInfo) || (fileInfo.type != TYPE_DIR)) // directory accessible?
return -2;
strncpy(sessions[id].workingDir, &realPath[len], MAX_PATH_LEN); // apply path
strncpy(sessions[id].workingDir, &realPath[len], MAX_PATH_LEN-1); // apply path
if(sessions[id].workingDir[0] == '\0')
strcpy(sessions[id].workingDir, "/");

View File

@ -97,7 +97,7 @@ void* ftpOpenDir(const char* path)
if(p)
{
p->findHandle = INVALID_HANDLE_VALUE;
strcpy(p->path, path);
strncpy(p->path, path,strlen(path));
}
return p;
}
@ -281,7 +281,7 @@ socket_t ftpEstablishDataConnection(int passive, ip_t *ip, port_t *port, int ses
BOOL on = 1;
unsigned len;
dataSocket = socket(AF_INET, SOCK_STREAM, 0);
if(dataSocket < 0)
if(dataSocket == INVALID_SOCKET)
return -1;
if(!passive)
@ -308,6 +308,8 @@ socket_t ftpEstablishDataConnection(int passive, ip_t *ip, port_t *port, int ses
clientAddr.sin_family = AF_INET;
clientAddr.sin_addr.s_addr = htonl(*ip);
clientAddr.sin_port = htons(*port);
clientAddr.sin_zero[0] = 0;
if(connect(dataSocket, (struct sockaddr *)&clientAddr, sizeof(clientAddr)))
{
if(VERBOSE_MODE_ENABLED) printf("In ftpEstablishDataConnection #3 about to Close socket = %d, for sessionId = %d\n",dataSocket, sessionId);
@ -325,6 +327,7 @@ socket_t ftpEstablishDataConnection(int passive, ip_t *ip, port_t *port, int ses
myAddr.sin_family = AF_INET;
myAddr.sin_addr.s_addr = INADDR_ANY;
myAddr.sin_port = htons(passivePort);
myAddr.sin_zero[0] = 0;
//myAddr.sin_port = htons(ftpGetPassivePort() + sessionId);
if(setsockopt(dataSocket, SOL_SOCKET, SO_REUSEADDR, (const char *)&on, sizeof(on)))
@ -388,10 +391,10 @@ socket_t ftpAcceptDataConnection(socket_t listner)
len = sizeof(clientinfo);
dataSocket = accept(listner, (struct sockaddr *)&clientinfo, &len);
if(dataSocket < 0)
if(dataSocket == INVALID_SOCKET)
{
if(VERBOSE_MODE_ENABLED) printf("ERROR In ftpAcceptDataConnection accept failed, dataSocket = %d, listner = %d\n", dataSocket,listner);
dataSocket = -1;
//dataSocket = -1;
}
else
{
@ -410,7 +413,7 @@ socket_t ftpAcceptDataConnection(socket_t listner)
ftpUntrackSocket(dataSocket);
ftpCloseSocket(&dataSocket);
dataSocket = -1;
dataSocket = INVALID_SOCKET;
}
return (socket_t)dataSocket;
@ -424,28 +427,27 @@ socket_t ftpCreateServerSocket(int portNumber)
int val = 1;
theServer = socket(AF_INET, SOCK_STREAM, 0);
if(theServer < 0)
if(theServer == INVALID_SOCKET)
return -1;
serverinfo.sin_family = AF_INET;
serverinfo.sin_addr.s_addr = INADDR_ANY;
serverinfo.sin_port = htons(portNumber);
serverinfo.sin_zero[0] = 0;
len = sizeof(serverinfo);
setsockopt(theServer, SOL_SOCKET, SO_REUSEADDR, (char *)&val, sizeof(val));
int opt_result = setsockopt(theServer, SOL_SOCKET, SO_REUSEADDR, (char *)&val, sizeof(val));
if(bind(theServer, (struct sockaddr *)&serverinfo, len))
{
if(VERBOSE_MODE_ENABLED) printf("\nERROR In ftpCreateServerSocket bind FAILED about to close listener socket = %d\n",theServer);
if(bind(theServer, (struct sockaddr *)&serverinfo, len)) {
if(VERBOSE_MODE_ENABLED) printf("\nERROR In ftpCreateServerSocket bind FAILED about to close listener socket = %d opt_result = %d\n",theServer,opt_result);
ftpUntrackSocket(theServer);
ftpCloseSocket(&theServer);
return -2;
}
if(listen(theServer, 100))
{
if(VERBOSE_MODE_ENABLED) printf("\nERROR In ftpCreateServerSocket listen FAILED about to close listener socket = %d\n",theServer);
if(listen(theServer, 100)) {
if(VERBOSE_MODE_ENABLED) printf("\nERROR In ftpCreateServerSocket listen FAILED about to close listener socket = %d opt_result = %d\n",theServer,opt_result);
ftpUntrackSocket(theServer);
ftpCloseSocket(&theServer);

View File

@ -639,14 +639,14 @@ void CHECK_FONT_PATH(const char *filename,const char *fontFamily,const char **fo
}
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("#1 Searching for font file [%s] result [%s]\n",(*path != NULL ? *path : "null"),(*font != NULL ? *font : "null"));
if( *font == NULL && fontFamily != NULL && strlen(fontFamily) > 0) {
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("#2 Searching for font [%s] family [%s]\n",(*font != NULL ? *font : "null"),(fontFamily != NULL ? fontFamily : "null"));
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("#2 Searching for font [%s] family [%s]\n",(*font != NULL ? *font : "null"),fontFamily);
string fileFound = findFontFamily(*font, fontFamily);
if(fileFound != "") {
*path = fileFound.c_str();
//*path = fileFound.c_str();
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("#2 candidate font file found [%s]\n",fileFound.c_str());
if( *path != NULL && strlen(*path) > 0 && fileExists(*path) == true ) {
if( fileFound.length() > 0 && fileExists(fileFound) == true ) {
if(*font) free((void*)*font);
*font = strdup(*path);
*font = strdup(fileFound.c_str());
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("#2 candidate font file has been set[%s]\n",(*font != NULL ? *font : "null"));
}
*path = NULL;
@ -677,10 +677,11 @@ const char* findFont(const char *firstFontToTry,const char *firstFontFamilyToTry
}
// Get user-specified font path
if(getenv("MEGAGLEST_FONT") != NULL || getenv("MEGAGLEST_FONT_FAMILY") != NULL) {
if(getenv("MEGAGLEST_FONT") != NULL) {
tryFont = getenv("MEGAGLEST_FONT");
string megaglest_font = safeCharPtrCopy(getenv("MEGAGLEST_FONT"),8095);
string megaglest_font_family = safeCharPtrCopy(getenv("MEGAGLEST_FONT_FAMILY"),8095);
if(megaglest_font != "" || megaglest_font_family != "") {
if(megaglest_font != "") {
tryFont = megaglest_font;
if(Text::DEFAULT_FONT_PATH_ABSOLUTE != "") {
tryFont = Text::DEFAULT_FONT_PATH_ABSOLUTE + "/" + extractFileFromDirectoryPath(tryFont);
@ -689,10 +690,10 @@ const char* findFont(const char *firstFontToTry,const char *firstFontFamilyToTry
replaceAll(tryFont, "/", "\\");
#endif
CHECK_FONT_PATH(tryFont.c_str(),getenv("MEGAGLEST_FONT_FAMILY"),&font,&path);
CHECK_FONT_PATH(tryFont.c_str(),megaglest_font_family.c_str(),&font,&path);
}
else {
CHECK_FONT_PATH(NULL,getenv("MEGAGLEST_FONT_FAMILY"),&font,&path);
CHECK_FONT_PATH(NULL,megaglest_font_family.c_str(),&font,&path);
}
}

View File

@ -1216,7 +1216,7 @@ void Model::loadG3d(const string &path, bool deletePixMapAfterLoad,
f = NULL;
char fileType[4]="";
memset(&fileType[0],0,4);
memcpy(&fileType[0],fileHeader.id,4);
memcpy(&fileType[0],fileHeader.id,3);
printf("In [%s::%s] file = [%s] fileheader.id = [%s][%c]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,path.c_str(),fileType,fileHeader.id[0]);
throw megaglest_runtime_error("Not a valid G3D model",true);
}
@ -1270,7 +1270,7 @@ void Model::loadG3d(const string &path, bool deletePixMapAfterLoad,
}
meshCount = Shared::PlatformByteOrder::fromCommonEndian(meshCount);
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("meshCount = %d\n",meshCount);
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("meshCount = %u\n",meshCount);
try {
meshes= new Mesh[meshCount];

View File

@ -1154,9 +1154,14 @@ float Pixmap2D::getComponentf(int x, int y, int component) const {
return c;
}
void Pixmap2D::setPixel(int x, int y, const uint8 *value) {
for(int i=0; i<components; ++i) {
int index = (w*y+x)*components+i;
void Pixmap2D::setPixel(int x, int y, const uint8 *value, int arraySize) {
if(arraySize > components) {
char szBuf[8096];
snprintf(szBuf,8096,"Invalid pixmap arraySize: %d for [%s], h = %d, w = %d, components = %d x = %d y = %d\n",arraySize,path.c_str(),h,w,components,x,y);
throw megaglest_runtime_error(szBuf);
}
for(int i = 0; i < components; ++i) {
int index = (w * y + x) * components + i;
if(index < 0 || (unsigned int)index >= getPixelByteCount()) {
char szBuf[8096];
snprintf(szBuf,8096,"Invalid pixmap index: %d for [%s], h = %d, w = %d, components = %d x = %d y = %d\n",index,path.c_str(),h,w,components,x,y);
@ -1168,8 +1173,14 @@ void Pixmap2D::setPixel(int x, int y, const uint8 *value) {
CalculatePixelsCRC(pixels,getPixelByteCount(), crc);
}
void Pixmap2D::setPixel(int x, int y, const float32 *value) {
for(int i=0; i<components; ++i) {
void Pixmap2D::setPixel(int x, int y, const float32 *value, int arraySize) {
if(arraySize > components) {
char szBuf[8096];
snprintf(szBuf,8096,"Invalid pixmap arraySize: %d for [%s], h = %d, w = %d, components = %d x = %d y = %d\n",arraySize,path.c_str(),h,w,components,x,y);
throw megaglest_runtime_error(szBuf);
}
for(int i = 0; i < components; ++i) {
int index = (w*y+x)*components+i;
if(index < 0 || (unsigned int)index >= getPixelByteCount()) {
char szBuf[8096];
@ -1244,19 +1255,19 @@ void Pixmap2D::setPixel(int x, int y, float p) {
CalculatePixelsCRC(pixels,getPixelByteCount(), crc);
}
void Pixmap2D::setPixels(const uint8 *value){
for(int i=0; i<w; ++i){
for(int j=0; j<h; ++j){
setPixel(i, j, value);
void Pixmap2D::setPixels(const uint8 *value, int arraySize) {
for(int i = 0; i < w; ++i) {
for(int j = 0; j < h; ++j) {
setPixel(i, j, value, arraySize);
}
}
CalculatePixelsCRC(pixels,getPixelByteCount(), crc);
}
void Pixmap2D::setPixels(const float32 *value){
for(int i=0; i<w; ++i){
for(int j=0; j<h; ++j){
setPixel(i, j, value);
void Pixmap2D::setPixels(const float32 *value, int arraySize) {
for(int i = 0; i < w; ++i) {
for(int j = 0; j < h; ++j) {
setPixel(i, j, value, arraySize);
}
}
CalculatePixelsCRC(pixels,getPixelByteCount(), crc);
@ -1372,10 +1383,10 @@ void Pixmap2D::subCopy(int x, int y, const Pixmap2D *sourcePixmap){
uint8 *pixel= new uint8[components];
for(int i=0; i<sourcePixmap->getW(); ++i){
for(int j=0; j<sourcePixmap->getH(); ++j){
for(int i = 0; i < sourcePixmap->getW(); ++i) {
for(int j = 0; j < sourcePixmap->getH(); ++j) {
sourcePixmap->getPixel(i, j, pixel);
setPixel(i+x, j+y, pixel);
setPixel(i+x, j+y, pixel, components);
}
}
CalculatePixelsCRC(pixels,getPixelByteCount(), crc);
@ -1393,10 +1404,10 @@ void Pixmap2D::copyImagePart(int x, int y, const Pixmap2D *sourcePixmap){
uint8 *pixel= new uint8[components];
for(int i=x; i<x+w; ++i){
for(int j=y; j<y+h; ++j){
for(int i = x; i < x + w; ++i) {
for(int j = y; j < y + h; ++j) {
sourcePixmap->getPixel(i, j, pixel);
setPixel(i-x, j-y, pixel);
setPixel(i-x, j-y, pixel, components);
}
}
CalculatePixelsCRC(pixels,getPixelByteCount(), crc);

View File

@ -922,6 +922,7 @@ void MapPreview::saveToFile(const string &path) {
strncpy(header.title, title.c_str(), MAX_TITLE_LENGTH);
strncpy(header.author, author.c_str(), MAX_AUTHOR_LENGTH);
strncpy(header.version2.short_desc, desc.c_str(), MAX_DESCRIPTION_LENGTH_VERSION2);
header.version2.short_desc[MAX_DESCRIPTION_LENGTH_VERSION2] = 0;
header.version2.magic= 0x01020304;
header.version2.cliffLevel= cliffLevel;
header.version2.cameraHeight= cameraHeight;

View File

@ -348,8 +348,8 @@ void findAll(const string &path, vector<string> &results, bool cutExtension, boo
/** Stupid win32 is searching for all files without extension when *. is
* specified as wildcard
*/
if(mypath.size() >= 2 && mypath.compare(max((size_t)0,mypath.size() - 2), 2, "*.") == 0) {
mypath = mypath.substr(0, max((size_t)0,mypath.size() - 2));
if((int)mypath.size() >= 2 && mypath.compare(max((int)0,(int)mypath.size() - 2), 2, "*.") == 0) {
mypath = mypath.substr(0, max((int)0,(int)mypath.size() - 2));
mypath += "*";
}
@ -525,7 +525,7 @@ bool EndsWith(const string &str, const string& key)
{
bool result = false;
if (str.length() >= key.length()) {
result = (0 == str.compare(max((size_t)0,str.length() - key.length()), key.length(), key));
result = (0 == str.compare(max((int)0,(int)str.length() - (int)key.length()), key.length(), key));
}
return result;
@ -1017,8 +1017,8 @@ uint32 getFolderTreeContentsCheckSumRecursively(const string &path, const string
// Stupid win32 is searching for all files without extension when *. is
// specified as wildcard
//
if(mypath.size() >= 2 && mypath.compare(max((size_t)0,mypath.size() - 2), 2, "*.") == 0) {
mypath = mypath.substr(0, max((size_t)0,mypath.size() - 2));
if((int)mypath.size() >= 2 && mypath.compare(max((int)0,(int)mypath.size() - 2), 2, "*.") == 0) {
mypath = mypath.substr(0, max((int)0,(int)mypath.size() - 2));
mypath += "*";
}
@ -1187,8 +1187,8 @@ vector<string> getFolderTreeContentsListRecursively(const string &path, const st
/** Stupid win32 is searching for all files without extension when *. is
* specified as wildcard
*/
if(mypath.size() >= 2 && mypath.compare(max((size_t)0,mypath.size() - 2), 2, "*.") == 0) {
mypath = mypath.substr(0, max((size_t)0,mypath.size() - 2));
if((int)mypath.size() >= 2 && mypath.compare(max((int)0,(int)mypath.size() - 2), 2, "*.") == 0) {
mypath = mypath.substr(0, max((int)0,(int)mypath.size() - 2));
mypath += "*";
}
@ -1338,8 +1338,8 @@ vector<std::pair<string,uint32> > getFolderTreeContentsCheckSumListRecursively(c
/** Stupid win32 is searching for all files without extension when *. is
* specified as wildcard
*/
if(mypath.size() >= 2 && mypath.compare(max((size_t)0,mypath.size() - 2), 2, "*.") == 0) {
mypath = mypath.substr(0, max((size_t)0,mypath.size() - 2));
if((int)mypath.size() >= 2 && mypath.compare(max((int)0,(int)mypath.size() - 2), 2, "*.") == 0) {
mypath = mypath.substr(0, max((int)0,(int)mypath.size() - 2));
mypath += "*";
}
@ -2424,17 +2424,29 @@ void ValueCheckerVault::checkItemInVault(const void *ptr,int value) const {
string getUserHome() {
string home_folder = "";
const char *homedir = getenv("HOME");
if (!homedir) {
home_folder = safeCharPtrCopy(getenv("HOME"),8095);
if(home_folder == "") {
#if _BSD_SOURCE || _SVID_SOURCE || _XOPEN_SOURCE >= 500 || _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED
struct passwd *pw = getpwuid(getuid());
homedir = pw->pw_dir;
#else
homedir = "";
home_folder = safeCharPtrCopy(pw->pw_dir,8095);
#endif
}
home_folder = homedir;
return home_folder;
}
string safeCharPtrCopy(const char *ptr,int maxLength) {
if(ptr == NULL) {
return "";
}
if(maxLength <= 0) {
maxLength = 8096;
}
char *pBuffer = new char[maxLength+1];
memset(pBuffer,0,maxLength+1);
memcpy(pBuffer,ptr,std::min((int)strlen(ptr),maxLength));
return pBuffer;
}
}}//end namespace

View File

@ -75,7 +75,7 @@ void dump_event (irc_session_t * session, const char * event, const char * origi
if ( cnt ) {
strcat (buf, "|");
}
strcat (buf, params[cnt]);
strncat (buf, params[cnt],std::min((int)strlen(params[cnt]),511));
}
addlog ("Event \"%s\", origin: \"%s\", params: %d [%s]", event, origin ? origin : "NULL", cnt, buf);

View File

@ -549,17 +549,16 @@ string getNetworkInterfaceBroadcastAddress(string ipAddress)
MIB_IPADDRTABLE * ipTable = NULL;
{
ULONG bufLen = 0;
for (int i=0; i<5; i++)
{
for (int i = 0; i < 5; i++) {
DWORD ipRet = GetIpAddrTable(ipTable, &bufLen, false);
if (ipRet == ERROR_INSUFFICIENT_BUFFER)
{
if (ipRet == ERROR_INSUFFICIENT_BUFFER) {
free(ipTable); // in case we had previously allocated it
ipTable = (MIB_IPADDRTABLE *) malloc(bufLen);
}
else if (ipRet == NO_ERROR) break;
else
{
else if(ipRet == NO_ERROR) {
break;
}
else {
free(ipTable);
ipTable = NULL;
break;
@ -567,8 +566,7 @@ string getNetworkInterfaceBroadcastAddress(string ipAddress)
}
}
if (ipTable)
{
if (ipTable) {
// Try to get the Adapters-info table, so we can given useful names to the IP
// addresses we are returning. Gotta call GetAdaptersInfo() up to 5 times to handle
// the potential race condition between the size-query call and the get-data call.
@ -576,17 +574,16 @@ string getNetworkInterfaceBroadcastAddress(string ipAddress)
IP_ADAPTER_INFO * pAdapterInfo = NULL;
{
ULONG bufLen = 0;
for (int i=0; i<5; i++)
{
for (int i = 0; i < 5; i++) {
DWORD apRet = GetAdaptersInfo(pAdapterInfo, &bufLen);
if (apRet == ERROR_BUFFER_OVERFLOW)
{
if (apRet == ERROR_BUFFER_OVERFLOW) {
free(pAdapterInfo); // in case we had previously allocated it
pAdapterInfo = (IP_ADAPTER_INFO *) malloc(bufLen);
}
else if (apRet == ERROR_SUCCESS) break;
else
{
else if(apRet == ERROR_SUCCESS) {
break;
}
else {
free(pAdapterInfo);
pAdapterInfo = NULL;
break;
@ -594,23 +591,18 @@ string getNetworkInterfaceBroadcastAddress(string ipAddress)
}
}
for (DWORD i=0; i<ipTable->dwNumEntries; i++)
{
for (DWORD i = 0; i < ipTable->dwNumEntries; i++) {
const MIB_IPADDRROW & row = ipTable->table[i];
// Now lookup the appropriate adaptor-name in the pAdaptorInfos, if we can find it
const char * name = NULL;
//const char * desc = NULL;
if (pAdapterInfo)
{
if (pAdapterInfo) {
IP_ADAPTER_INFO * next = pAdapterInfo;
while((next)&&(name==NULL))
{
while((next)&&(name==NULL)) {
IP_ADDR_STRING * ipAddr = &next->IpAddressList;
while(ipAddr)
{
if (Inet_AtoN(ipAddr->IpAddress.String) == ntohl(row.dwAddr))
{
while(ipAddr) {
if (Inet_AtoN(ipAddr->IpAddress.String) == ntohl(row.dwAddr)) {
name = next->AdapterName;
//desc = next->Description;
break;
@ -620,19 +612,23 @@ string getNetworkInterfaceBroadcastAddress(string ipAddress)
next = next->Next;
}
}
if (name == NULL)
{
if (name == NULL) {
name = "";
}
uint32 ipAddr = ntohl(row.dwAddr);
uint32 netmask = ntohl(row.dwMask);
uint32 baddr = ipAddr & netmask;
if (row.dwBCastAddr) baddr |= ~netmask;
if (row.dwBCastAddr) {
baddr |= ~netmask;
}
char ifaAddrStr[32]; Ip::Inet_NtoA(ipAddr, ifaAddrStr);
char maskAddrStr[32]; Ip::Inet_NtoA(netmask, maskAddrStr);
char dstAddrStr[32]; Ip::Inet_NtoA(baddr, dstAddrStr);
char ifaAddrStr[32];
Ip::Inet_NtoA(ipAddr, ifaAddrStr);
char maskAddrStr[32];
Ip::Inet_NtoA(netmask, maskAddrStr);
char dstAddrStr[32];
Ip::Inet_NtoA(baddr, dstAddrStr);
//printf(" Found interface: name=[%s] desc=[%s] address=[%s] netmask=[%s] broadcastAddr=[%s]\n", name, desc?desc:"unavailable", ifaAddrStr, maskAddrStr, dstAddrStr);
if(strcmp(ifaAddrStr,ipAddress.c_str()) == 0) {
broadCastAddress = dstAddrStr;
@ -2434,6 +2430,9 @@ Socket *ServerSocket::accept(bool errorOnFail) {
throwException(szBuf);
}
else {
::close(newSock);
newSock = INVALID_SOCKET;
return NULL;
}
@ -2925,7 +2924,8 @@ void BroadCastSocketThread::execute() {
strcat(buff,":");
strcat(buff,ipList[idx1].c_str());
strcat(buff,":");
strcat(buff,intToStr(this->boundPort).c_str());
string port_string = intToStr(this->boundPort);
strncat(buff,port_string.c_str(),std::min((int)port_string.length(),100));
}
if(difftime((long int)time(NULL),elapsed) >= 1 && getQuitStatus() == false) {

View File

@ -260,6 +260,10 @@ string PlatformExceptionHandler::getStackTrace() {
SymCleanup(hProcess);
}
#endif
#ifndef __MINGW32__
delete [] pSym;
#endif
return result;
}

View File

@ -130,7 +130,7 @@ int g3d2xml(FILE *infile, FILE *outfile)
struct ModelHeader modelHeader;
struct MeshHeader meshHeader;
size_t nBytes;
uint8 textureName[NAMESIZE];
uint8 textureName[NAMESIZE+1];
float32 *fdata;
uint32 *idata;
unsigned int ii, jj, kk;
@ -226,7 +226,8 @@ int g3d2xml(FILE *infile, FILE *outfile)
/* read / write the texture name if present */
if (meshHeader.textures)
{
nBytes = sizeof(textureName);
memset(&textureName[0],0,NAMESIZE+1);
nBytes = NAMESIZE;
if (fread(&textureName, nBytes, 1, infile) != 1)
{
printf("Could not read texture name!\n");

View File

@ -245,7 +245,7 @@ int processMesh(xmlNode *n, FILE *outfile)
float32 color[3];
struct MeshHeader mh;
uint8 texname[NAMESIZE];
uint8 texname[NAMESIZE+1];
int foundFlag = FALSE;
xmlNode *texn = NULL;
@ -304,7 +304,7 @@ int processMesh(xmlNode *n, FILE *outfile)
printf("Could not find <Texture> element!\n");
return FALSE;
}
memset(texname, 0, NAMESIZE);
memset(texname, 0, NAMESIZE+1);
strncpy((char*)texname,
(char*)xmlGetProp(texn, (xmlChar*)"name"), NAMESIZE);
fwrite(texname, NAMESIZE, 1, outfile);