- 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

@@ -145,7 +145,7 @@ Chrono::Chrono(bool autoStart) {
lastResult = 0;
lastMultiplier = 0;
lastStopped = false;
startCount = 0;
if(autoStart == true) {
start();
}
@@ -204,11 +204,11 @@ int64 Chrono::queryCounter(int multiplier) {
int64 result = 0;
if(stopped) {
result = multiplier*accumCount/freq;
result = (int64)multiplier * (int64)(accumCount / freq);
}
else {
Uint32 endCount = SDL_GetTicks();
result = multiplier*(accumCount+endCount-startCount)/freq;
result = (int64)multiplier * (int64)((accumCount + endCount - startCount) / freq);
lastTickCount = endCount;
}

View File

@@ -1203,7 +1203,7 @@ void FTPClientThread::execute() {
getTempFileFromServer(file);
}
else {
safeMutex5.ReleaseLock();
safeMutex6.ReleaseLock();
}
if(this->getQuitStatus() == false) {

View File

@@ -809,6 +809,8 @@ Socket::Socket() {
dataSynchAccessorWrite = new Mutex();
inSocketDestructorSynchAccessor = new Mutex();
lastSocketError = 0;
lastDebugEvent = 0;
lastThreadedPing = 0;
MutexSafeWrapper safeMutexSocketDestructorFlag(inSocketDestructorSynchAccessor,CODE_AT_LINE);
inSocketDestructorSynchAccessor->setOwnerId(CODE_AT_LINE);
@@ -1466,6 +1468,7 @@ int Socket::receive(void *data, int dataSize, bool tryReceiveUntilDataSizeMet) {
SafeSocketBlockToggleWrapper::SafeSocketBlockToggleWrapper(Socket *socket, bool toggle) {
this->socket = socket;
if(this->socket != NULL) {
this->originallyBlocked = socket->getBlock();
this->newBlocked = toggle;
@@ -1474,6 +1477,10 @@ SafeSocketBlockToggleWrapper::SafeSocketBlockToggleWrapper(Socket *socket, bool
socket->setBlock(this->newBlocked);
}
}
else {
this->originallyBlocked = false;
this->newBlocked = false;
}
}
void SafeSocketBlockToggleWrapper::Restore() {
@@ -2068,15 +2075,15 @@ void BroadCastClientSocketThread::execute() {
int val = 1;
#ifndef WIN32
setsockopt(bcfd, SOL_SOCKET, SO_REUSEADDR, &val, sizeof(val));
int opt_result = setsockopt(bcfd, SOL_SOCKET, SO_REUSEADDR, &val, sizeof(val));
#else
setsockopt(bcfd, SOL_SOCKET, SO_REUSEADDR, (char *)&val, sizeof(val));
int opt_result = setsockopt(bcfd, SOL_SOCKET, SO_REUSEADDR, (char *)&val, sizeof(val));
#endif
if(::bind( bcfd, (struct sockaddr *)&bcaddr, sizeof(bcaddr) ) < 0 ) {
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"bind failed: %s\n", Socket::getLastSocketErrorFormattedText().c_str());
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"bind failed: %s opt_result = %d\n", Socket::getLastSocketErrorFormattedText().c_str(),opt_result);
}
else {
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] opt_result = %d\n",__FILE__,__FUNCTION__,__LINE__,opt_result);
Socket::setBlock(false, bcfd);
@@ -2314,19 +2321,20 @@ void ServerSocket::bind(int port) {
addr.sin_addr.s_addr= INADDR_ANY;
}
addr.sin_port= htons(port);
addr.sin_zero[0] = 0;
int val = 1;
#ifndef WIN32
setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &val, sizeof(val));
int opt_result = setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &val, sizeof(val));
#else
setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char *)&val, sizeof(val));
int opt_result = setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char *)&val, sizeof(val));
#endif
int err= ::bind(sock, reinterpret_cast<sockaddr*>(&addr), sizeof(addr));
if(err < 0) {
char szBuf[8096]="";
snprintf(szBuf, 8096,"In [%s::%s] Error binding socket sock = " PLATFORM_SOCKET_FORMAT_TYPE ", address [%s] port = %d err = %d, error = %s\n",__FILE__,__FUNCTION__,sock,this->bindSpecificAddress.c_str(),port,err,getLastSocketErrorFormattedText().c_str());
snprintf(szBuf, 8096,"In [%s::%s] Error binding socket sock = " PLATFORM_SOCKET_FORMAT_TYPE ", address [%s] port = %d err = %d, error = %s opt_result = %d\n",__FILE__,__FUNCTION__,sock,this->bindSpecificAddress.c_str(),port,err,getLastSocketErrorFormattedText().c_str(),opt_result);
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"%s",szBuf);
snprintf(szBuf, 8096,"Error binding socket sock = %d, address [%s] port = %d err = %d, error = %s\n",sock,this->bindSpecificAddress.c_str(),port,err,getLastSocketErrorFormattedText().c_str());
@@ -2399,8 +2407,8 @@ Socket *ServerSocket::accept(bool errorOnFail) {
PLATFORM_SOCKET newSock=0;
char client_host[100]="";
const int max_attempts = 100;
for(int attempt = 0; attempt < max_attempts; ++attempt) {
//const int max_attempts = 100;
//for(int attempt = 0; attempt < max_attempts; ++attempt) {
struct sockaddr_in cli_addr;
socklen_t clilen = sizeof(cli_addr);
client_host[0]='\0';
@@ -2415,12 +2423,12 @@ Socket *ServerSocket::accept(bool errorOnFail) {
int lastSocketError = getLastSocketError();
if(lastSocketError == PLATFORM_SOCKET_TRY_AGAIN) {
if(attempt+1 >= max_attempts) {
return NULL;
}
else {
//if(attempt+1 >= max_attempts) {
// return NULL;
//}
//else {
sleep(0);
}
//}
}
if(errorOnFail == true) {
throwException(szBuf);
@@ -2448,8 +2456,8 @@ Socket *ServerSocket::accept(bool errorOnFail) {
return NULL;
}
break;
}
//break;
//}
Socket *result = new Socket(newSock);
result->setIpAddress((client_host[0] != '\0' ? client_host : ""));
return result;

View File

@@ -68,32 +68,33 @@ const char * getDialogCommand() {
}
bool showMessage(std::string warning,string writepath) {
bool guiMessage = false;
const char * dialogCommand = getDialogCommand();
if (dialogCommand) {
std::string command = dialogCommand;
bool guiMessage = false;
const char * dialogCommand = getDialogCommand();
if (dialogCommand) {
std::string command = dialogCommand;
string text_file = writepath + "/mg_dialog_text.txt";
{
FILE *fp = fopen(text_file.c_str(),"wt");
if (fp != NULL) {
fputs(warning.c_str(),fp);
fclose(fp);
string text_file = writepath + "/mg_dialog_text.txt";
{
FILE *fp = fopen(text_file.c_str(),"wt");
if (fp != NULL) {
fputs(warning.c_str(),fp);
fclose(fp);
}
}
}
//command += " --title \"Error\" --msgbox \"`printf \"" + warning + "\"`\"";
command += " --title \"Error\" --text-info --filename=" + text_file;
//command += " --title \"Error\" --msgbox \"`printf \"" + warning + "\"`\"";
command += " --title \"Error\" --text-info --filename=" + text_file;
//printf("\n\n\nzenity command [%s]\n\n\n",command.c_str());
//printf("\n\n\nzenity command [%s]\n\n\n",command.c_str());
FILE *fp = popen(command.c_str(),"r");
if (fp != 0)
guiMessage = true;
pclose(fp);
}
FILE *fp = popen(command.c_str(),"r");
if (fp != 0) {
guiMessage = true;
pclose(fp);
}
}
return guiMessage;
return guiMessage;
}
void message(string message, bool isNonGraphicalModeEnabled,string writepath) {

View File

@@ -107,7 +107,7 @@ public:
sleep(10);
if(base_thread->getRunningStatus() == true || base_thread->getExecutingTask() == true) {
if(Thread::getEnableVerboseMode()) printf("\n\n\n$$$$$$$$$$$$$$$$$$$$$$$$$$$ cleanupPendingThread Line: %d thread = %p [%s]\n",__LINE__,thread,(base_thread != NULL ? base_thread->getUniqueID().c_str() : "n/a"));
if(Thread::getEnableVerboseMode()) printf("\n\n\n$$$$$$$$$$$$$$$$$$$$$$$$$$$ cleanupPendingThread Line: %d thread = %p [%s]\n",__LINE__,thread,base_thread->getUniqueID().c_str());
char szBuf[8096]="";
snprintf(szBuf,8095,"In [%s::%s Line: %d] cannot delete active thread: getRunningStatus(): %d getExecutingTask: %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,base_thread->getRunningStatus(),base_thread->getExecutingTask());
@@ -118,8 +118,9 @@ public:
if(Thread::getEnableVerboseMode()) printf("!!!! cleanupPendingThread Line: %d thread = %p [%s]\n",__LINE__,thread,(base_thread != NULL ? base_thread->getUniqueID().c_str() : "n/a"));
delete thread;
thread = NULL;
if(Thread::getEnableVerboseMode()) printf("!!!! cleanupPendingThread Line: %d thread = %p [%s]\n",__LINE__,thread,(base_thread != NULL ? base_thread->getUniqueID().c_str() : "n/a"));
if(Thread::getEnableVerboseMode()) printf("!!!! cleanupPendingThread Line: %d thread = NULL [%s]\n",__LINE__,(base_thread != NULL ? base_thread->getUniqueID().c_str() : "n/a"));
}
}