- bugfixes for coverity reported issues

- new bash parameters for build-mg.sh (in prep for coverity automation)
- updated travis build to use new bash param
This commit is contained in:
SoftCoder
2013-12-17 17:35:51 -08:00
parent d8160c1065
commit e3996ceb92
15 changed files with 147 additions and 59 deletions

View File

@@ -151,6 +151,7 @@ int zipfile_tool(int argc, const char *argv[]) {
if (deflateInit(&stream, level) != Z_OK) {
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("deflateInit() failed!\n");
if(pInfile) fclose(pInfile);
return EXIT_FAILURE;
}
@@ -217,6 +218,7 @@ int zipfile_tool(int argc, const char *argv[]) {
if (fread(s_inbuf, 1, n, pInfile) != n) {
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("Failed reading from input file!\n");
if(pOutfile) fclose(pOutfile);
return EXIT_FAILURE;
}

View File

@@ -272,6 +272,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(20);
myAddr.sin_zero[0] = 0;
if(bind(dataSocket, (struct sockaddr *)&myAddr, sizeof(myAddr)))
{
if(VERBOSE_MODE_ENABLED) printf("In ftpEstablishDataConnection #2 about to Close socket = %d, for sessionId = %d\n",dataSocket, sessionId);
@@ -283,6 +284,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);

View File

@@ -800,8 +800,10 @@ void Mesh::load(int meshIndex, const string &dir, FILE *f, TextureManager *textu
uint32 flag= 1;
for(int i = 0; i < meshTextureCount; ++i) {
if(meshHeader.textures & flag) {
uint8 cMapPath[mapPathSize];
uint8 cMapPath[mapPathSize+1];
memset(&cMapPath[0],0,mapPathSize+1);
readBytes = fread(cMapPath, mapPathSize, 1, f);
cMapPath[mapPathSize] = 0;
if(readBytes != 1 && mapPathSize != 0) {
char szBuf[8096]="";
snprintf(szBuf,8096,"fread returned wrong size = " MG_SIZE_T_SPECIFIER " [%u] on line: %d.",readBytes,mapPathSize,__LINE__);
@@ -810,7 +812,7 @@ void Mesh::load(int meshIndex, const string &dir, FILE *f, TextureManager *textu
Shared::PlatformByteOrder::fromEndianTypeArray<uint8>(cMapPath, mapPathSize);
char mapPathString[mapPathSize+1]="";
memset(&mapPathString[0],0,mapPathSize);
memset(&mapPathString[0],0,mapPathSize+1);
memcpy(&mapPathString[0],reinterpret_cast<char*>(cMapPath),mapPathSize);
string mapPath= toLower(mapPathString);
@@ -1211,13 +1213,14 @@ void Model::loadG3d(const string &path, bool deletePixMapAfterLoad,
}
fromEndianFileHeader(fileHeader);
if(strncmp(reinterpret_cast<char*>(fileHeader.id), "G3D", 3) != 0) {
char fileId[4] = "";
memset(&fileId[0],0,4);
memcpy(&fileId[0],reinterpret_cast<char*>(fileHeader.id),3);
if(strncmp(fileId, "G3D", 3) != 0) {
fclose(f);
f = NULL;
char fileType[4]="";
memset(&fileType[0],0,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]);
printf("In [%s::%s] file = [%s] fileheader.id = [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,path.c_str(),fileId);
throw megaglest_runtime_error("Not a valid G3D model",true);
}
fileVersion= fileHeader.version;

View File

@@ -114,6 +114,10 @@ std::pair<SDL_Surface*,unsigned char*> Texture2D::CreateSDLSurface(bool newPixel
/* Use the surface width and height expanded to powers of 2 */
//int w = powerOfTwo(surface->w);
//int h = powerOfTwo(surface->h);
if(result.first == NULL) {
throw megaglest_runtime_error("result.first == NULL");
}
int w = result.first->w;
int h = result.first->h;

View File

@@ -920,7 +920,9 @@ void MapPreview::saveToFile(const string &path) {
header.heightFactor = heightFactor;
header.waterLevel = waterLevel;
strncpy(header.title, title.c_str(), MAX_TITLE_LENGTH);
header.title[MAX_TITLE_LENGTH-1] = 0;
strncpy(header.author, author.c_str(), MAX_AUTHOR_LENGTH);
header.author[MAX_AUTHOR_LENGTH-1] = 0;
strncpy(header.version2.short_desc, desc.c_str(), MAX_DESCRIPTION_LENGTH_VERSION2);
header.version2.short_desc[MAX_DESCRIPTION_LENGTH_VERSION2-1] = 0;
header.version2.magic= 0x01020304;

View File

@@ -4185,7 +4185,7 @@ mz_bool mz_zip_writer_add_mem_ex(mz_zip_archive *pZip, const char *pArchive_name
{
mz_uint16 method = 0, dos_time = 0, dos_date = 0;
mz_uint level, ext_attributes = 0, num_alignment_padding_bytes;
mz_uint64 local_dir_header_ofs = pZip->m_archive_size, cur_archive_file_ofs = pZip->m_archive_size, comp_size = 0;
mz_uint64 local_dir_header_ofs = 0, cur_archive_file_ofs = 0, comp_size = 0;
size_t archive_name_size;
mz_uint8 local_dir_header[MZ_ZIP_LOCAL_DIR_HEADER_SIZE];
tdefl_compressor *pComp = NULL;
@@ -4200,6 +4200,9 @@ mz_bool mz_zip_writer_add_mem_ex(mz_zip_archive *pZip, const char *pArchive_name
if ((!pZip) || (!pZip->m_pState) || (pZip->m_zip_mode != MZ_ZIP_MODE_WRITING) || ((buf_size) && (!pBuf)) || (!pArchive_name) || ((comment_size) && (!pComment)) || (pZip->m_total_files == 0xFFFF) || (level > MZ_UBER_COMPRESSION))
return MZ_FALSE;
local_dir_header_ofs = pZip->m_archive_size;
cur_archive_file_ofs = pZip->m_archive_size;
pState = pZip->m_pState;
if ((!(level_and_flags & MZ_ZIP_FLAG_COMPRESSED_DATA)) && (uncomp_size))
@@ -4336,7 +4339,7 @@ mz_bool mz_zip_writer_add_file(mz_zip_archive *pZip, const char *pArchive_name,
{
mz_uint uncomp_crc32 = MZ_CRC32_INIT, level, num_alignment_padding_bytes;
mz_uint16 method = 0, dos_time = 0, dos_date = 0, ext_attributes = 0;
mz_uint64 local_dir_header_ofs = pZip->m_archive_size, cur_archive_file_ofs = pZip->m_archive_size, uncomp_size = 0, comp_size = 0;
mz_uint64 local_dir_header_ofs = 0, cur_archive_file_ofs = 0, uncomp_size = 0, comp_size = 0;
size_t archive_name_size;
mz_uint8 local_dir_header[MZ_ZIP_LOCAL_DIR_HEADER_SIZE];
MZ_FILE *pSrc_file = NULL;
@@ -4352,6 +4355,9 @@ mz_bool mz_zip_writer_add_file(mz_zip_archive *pZip, const char *pArchive_name,
if (!mz_zip_writer_validate_archive_name(pArchive_name))
return MZ_FALSE;
local_dir_header_ofs = pZip->m_archive_size;
cur_archive_file_ofs = pZip->m_archive_size;
archive_name_size = strlen(pArchive_name);
if (archive_name_size > 0xFFFF)
return MZ_FALSE;

View File

@@ -2144,17 +2144,16 @@ void BroadCastClientSocketThread::execute() {
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] unknown error\n",__FILE__,__FUNCTION__,__LINE__);
}
}
}
#ifndef WIN32
::close(bcfd);
bcfd = INVALID_SOCKET;
::close(bcfd);
bcfd = INVALID_SOCKET;
#else
::closesocket(bcfd);
bcfd = INVALID_SOCKET;
::closesocket(bcfd);
bcfd = INVALID_SOCKET;
#endif
}
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
// Here we callback into the implementer class
@@ -2866,6 +2865,15 @@ void BroadCastSocketThread::execute() {
//char subnetmask[MAX_NIC_COUNT][100]; // Subnet mask to broadcast to
//struct hostent* myhostent=NULL;
for(unsigned int idx = 0; idx < (unsigned int)MAX_NIC_COUNT; idx++) {
memset( &bcLocal[idx], 0, sizeof( struct sockaddr_in));
#ifdef WIN32
bcfd[idx] = INVALID_SOCKET;
#else
bcfd[idx] = INVALID_SOCKET;
#endif
}
/* get my host name */
gethostname(myhostname,100);
//struct hostent*myhostent = gethostbyname(myhostname);
@@ -2926,15 +2934,16 @@ void BroadCastSocketThread::execute() {
// Send this machine's host name and address in hostname:n.n.n.n format
snprintf(buff,1024,"%s",myhostname);
for(unsigned int idx1 = 0; idx1 < ipList.size(); idx1++) {
strcat(buff,":");
strcat(buff,ipList[idx1].c_str());
strcat(buff,":");
string port_string = intToStr(this->boundPort);
#ifdef WIN32
strncat(buff,port_string.c_str(),min((int)port_string.length(),100));
#else
strncat(buff,port_string.c_str(),std::min((int)port_string.length(),100));
#endif
// strcat(buff,":");
// strcat(buff,ipList[idx1].c_str());
// strcat(buff,":");
// string port_string = intToStr(this->boundPort);
//#ifdef WIN32
// strncat(buff,port_string.c_str(),min((int)port_string.length(),100));
//#else
// strncat(buff,port_string.c_str(),std::min((int)port_string.length(),100));
//#endif
snprintf(buff,1024,"%s:%s:%d",buff,ipList[idx1].c_str(),this->boundPort);
}
if(difftime((long int)time(NULL),elapsed) >= 1 && getQuitStatus() == false) {

View File

@@ -506,6 +506,16 @@ void SystemFlags::logDebugEntry(DebugType type, string debugEntry, time_t debugT
int idx = 1;
for(idx = 1; idx <= 100; ++idx) {
newlockfile = lockfile + intToStr(idx);
if(SystemFlags::lockFile != -1) {
#ifndef WIN32
close(SystemFlags::lockFile);
#else
_close(SystemFlags::lockFile);
#endif
SystemFlags::lockFile = -1;
SystemFlags::lockFileCountIndex = -1;
}
//SystemFlags::lockFile = open(newlockfile.c_str(), O_WRONLY | O_CREAT | O_EXCL, S_IRUSR|S_IWUSR);
#ifndef WIN32
SystemFlags::lockFile = open(newlockfile.c_str(), O_WRONLY | O_CREAT, S_IREAD | S_IWRITE);