- coverity based bug fixes - round #1

This commit is contained in:
SoftCoder
2013-12-13 23:04:12 -08:00
parent c887b0c357
commit b9d6b38e8f
53 changed files with 651 additions and 416 deletions

View File

@@ -605,7 +605,7 @@ string findFontFamily(const char* font, const char *fontFamily) {
fs = FcFontSetCreate();
match = FcFontMatch(0, pat, &result);
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("Trying fontconfig for fontfamily [%s]\n",(fontFamily != NULL ? fontFamily : "null"));
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("Trying fontconfig for fontfamily [%s]\n",fontFamily);
if (match) FcFontSetAdd(fs, match);
if (pat) FcPatternDestroy(pat);
@@ -649,8 +649,9 @@ void CHECK_FONT_PATH(const char *filename,const char *fontFamily,const char **fo
*font = strdup(*path);
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("#2 candidate font file has been set[%s]\n",(*font != NULL ? *font : "null"));
}
*path = NULL;
}
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("#2 Searching for font family [%s] result [%s]\n",(fontFamily != NULL ? fontFamily : "null"),(*font != NULL ? *font : "null"));
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("#2 Searching for font family [%s] result [%s]\n",fontFamily,(*font != NULL ? *font : "null"));
}
}

View File

@@ -70,11 +70,12 @@ TextFTGL::TextFTGL(FontTextHandlerType type) : Text(type) {
}
if(ftFont->Error()) {
printf("FTGL: error loading font: %s\n", fontFile);
string fontFileName = (fontFile != NULL ? fontFile : "n/a");
printf("FTGL: error loading font: %s\n", fontFileName.c_str());
delete ftFont; ftFont = NULL;
free((void*)fontFile);
if(fontFile != NULL) free((void*)fontFile);
fontFile = NULL;
throw megaglest_runtime_error(string("FTGL: error loading font: ") + string(fontFile));
throw megaglest_runtime_error(string("FTGL: error loading font: ") + fontFileName);
}
free((void*)fontFile);
fontFile = NULL;

View File

@@ -537,7 +537,12 @@ void Mesh::loadV2(int meshIndex, const string &dir, FILE *f, TextureManager *tex
}
opacity = Shared::PlatformByteOrder::fromCommonEndian(opacity);
fseek(f, sizeof(Vec4f)*(meshHeader.colorFrameCount-1), SEEK_CUR);
int seek_result = fseek(f, sizeof(Vec4f)*(meshHeader.colorFrameCount-1), SEEK_CUR);
if(seek_result != 0) {
char szBuf[8096]="";
snprintf(szBuf,8096,"fseek returned failure = %d [%u] on line: %d.",seek_result,indexCount,__LINE__);
throw megaglest_runtime_error(szBuf);
}
readBytes = fread(indices, sizeof(uint32)*indexCount, 1, f);
if(readBytes != 1 && indexCount != 0) {
char szBuf[8096]="";
@@ -677,7 +682,13 @@ void Mesh::loadV3(int meshIndex, const string &dir, FILE *f,
}
opacity = Shared::PlatformByteOrder::fromCommonEndian(opacity);
fseek(f, sizeof(Vec4f)*(meshHeader.colorFrameCount-1), SEEK_CUR);
int seek_result = fseek(f, sizeof(Vec4f)*(meshHeader.colorFrameCount-1), SEEK_CUR);
if(seek_result != 0) {
char szBuf[8096]="";
snprintf(szBuf,8096,"fseek returned failure = %d [%u] on line: %d.",seek_result,indexCount,__LINE__);
throw megaglest_runtime_error(szBuf);
}
readBytes = fread(indices, sizeof(uint32)*indexCount, 1, f);
if(readBytes != 1 && indexCount != 0) {
char szBuf[8096]="";
@@ -798,7 +809,10 @@ void Mesh::load(int meshIndex, const string &dir, FILE *f, TextureManager *textu
}
Shared::PlatformByteOrder::fromEndianTypeArray<uint8>(cMapPath, mapPathSize);
string mapPath= toLower(reinterpret_cast<char*>(cMapPath));
char mapPathString[mapPathSize+1]="";
memset(&mapPathString[0],0,mapPathSize);
memcpy(&mapPathString[0],reinterpret_cast<char*>(cMapPath),mapPathSize);
string mapPath= toLower(mapPathString);
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);
@@ -1074,6 +1088,7 @@ Model::Model() {
meshCount = 0;
meshes = NULL;
fileVersion = 0;
textureManager = NULL;
lastTData = -1;
lastCycleData = false;
@@ -1199,7 +1214,10 @@ void Model::loadG3d(const string &path, bool deletePixMapAfterLoad,
if(strncmp(reinterpret_cast<char*>(fileHeader.id), "G3D", 3) != 0) {
fclose(f);
f = NULL;
printf("In [%s::%s] file = [%s] fileheader.id = [%s][%c]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,path.c_str(),reinterpret_cast<char*>(fileHeader.id),fileHeader.id[0]);
char fileType[4]="";
memset(&fileType[0],0,4);
memcpy(&fileType[0],fileHeader.id,4);
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);
}
fileVersion= fileHeader.version;
@@ -1833,7 +1851,6 @@ const unsigned int BaseColorPickEntity::p = 64007;
const unsigned int BaseColorPickEntity::k = 43067;
unsigned int BaseColorPickEntity::nextColorRGB = BaseColorPickEntity::k;
//Mutex BaseColorPickEntity::mutexNextColorID;
unsigned char BaseColorPickEntity::nextColorID[COLOR_COMPONENTS] = { 1, 1, 1, 0 };
auto_ptr<PixelBufferWrapper> BaseColorPickEntity::pbo;
@@ -1853,7 +1870,6 @@ BaseColorPickEntity::BaseColorPickEntity() {
}
bool BaseColorPickEntity::get_next_assign_color(unsigned char *assign_to) {
//MutexSafeWrapper safeMutex(&mutexNextColorID);
if(assign_to == NULL) {
throw megaglest_runtime_error("assign_to == NULL");
@@ -1969,7 +1985,6 @@ void BaseColorPickEntity::assign_color_using_loop(unsigned char *assign_to) {
}
void BaseColorPickEntity::recycleUniqueColor() {
//MutexSafeWrapper safeMutex(&mutexNextColorID);
vector<unsigned char> reUseColor;
reUseColor.push_back(uniqueColorID[0]);
@@ -1993,8 +2008,6 @@ void BaseColorPickEntity::recycleUniqueColor() {
}
void BaseColorPickEntity::resetUniqueColors() {
//MutexSafeWrapper safeMutex(&mutexNextColorID);
BaseColorPickEntity::nextColorRGB = BaseColorPickEntity::k;
BaseColorPickEntity::nextColorID[0] = 1;

View File

@@ -124,6 +124,7 @@ ParticleSystem::ParticleSystem(int particleCount) {
particleSystemStartDelay= 0;
this->particleOwner = NULL;
this->particleSize = 0.0f;
}
ParticleSystem::~ParticleSystem() {

View File

@@ -802,7 +802,7 @@ void Pixmap1D::init(int w, int components){
}
uint64 Pixmap1D::getPixelByteCount() const {
return (w * components);
return ((uint64)w * (uint64)components);
}
void Pixmap1D::deletePixels() {
@@ -955,7 +955,7 @@ void Pixmap2D::init(int w, int h, int components) {
}
uint64 Pixmap2D::getPixelByteCount() const {
return (h * w * components);
return ((uint64)h * (uint64)w * (uint64)components);
}
void Pixmap2D::deletePixels() {
@@ -1456,7 +1456,7 @@ void Pixmap3D::init(int w, int h, int d, int components){
}
uint64 Pixmap3D::getPixelByteCount() const {
return (h * w * d * components);
return ((uint64)h * (uint64)w * (uint64)d * (uint64)components);
}
void Pixmap3D::init(int d, int components){

View File

@@ -108,7 +108,7 @@ std::pair<SDL_Surface*,unsigned char*> Texture2D::CreateSDLSurface(bool newPixel
delete[] surfData;
result.second = NULL;
}
else {
// SDL_Surface *prepGLTexture(SDL_Surface *surface, GLfloat *texCoords = NULL, const bool
// freeSource = false) {
/* Use the surface width and height expanded to powers of 2 */
@@ -208,6 +208,7 @@ std::pair<SDL_Surface*,unsigned char*> Texture2D::CreateSDLSurface(bool newPixel
result.first = image;
// }
}
return result;
}