- bugfixes found from cppcheck

This commit is contained in:
Mark Vejvoda
2011-08-31 19:44:19 +00:00
parent f542ce36e4
commit 3af608151e
12 changed files with 351 additions and 82 deletions

View File

@@ -1873,9 +1873,13 @@ bool searchAndReplaceTextInFile(string fileName, string findText, string replace
#endif
if(fp1 == NULL) {
if(fp2) fclose(fp2);
throw runtime_error("cannot open input file [" + fileName + "]");
}
if(fp2 == NULL) {
if(fp1) fclose(fp1);
throw runtime_error("cannot open output file [" + tempfileName + "]");
}

View File

@@ -99,6 +99,13 @@ static size_t my_fwrite(void *buffer, size_t size, size_t nmemb, void *stream) {
out->isValidXfer = true;
}
else if(out == NULL) {
if(SystemFlags::VERBOSE_MODE_ENABLED) printf ("===> #2 FTP Client thread FAILED to open file for writing [%s]\n",fullFilePath.c_str());
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"===> #2 FTP Client thread FAILED to open file for writing [%s]\n",fullFilePath.c_str());
SystemFlags::OutputDebug(SystemFlags::debugError,"===> #2 FTP Client thread FAILED to open file for writing [%s]\n",fullFilePath.c_str());
return -1; /* failure, can't open file to write */
}
size_t result = fwrite(buffer, size, nmemb, out->stream);
if(result != nmemb) {
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("===> FTP Client thread FAILED to write data chunk to file [%s] nmemb = %lu, result = %lu\n",fullFilePath.c_str(),nmemb,result);

View File

@@ -2312,7 +2312,8 @@ void BroadCastSocketThread::execute() {
PLATFORM_SOCKET bcfd[MAX_NIC_COUNT]; // The socket used for the broadcast.
bool one = true; // Parameter for "setscokopt".
int pn=0; // The number of the packet broadcasted.
char buff[1024]=""; // Buffers the data to be broadcasted.
const int buffMaxSize=1024;
char buff[buffMaxSize]=""; // Buffers the data to be broadcasted.
char myhostname[100]=""; // hostname of local machine
//char subnetmask[MAX_NIC_COUNT][100]; // Subnet mask to broadcast to
struct hostent* myhostent=NULL;
@@ -2375,14 +2376,16 @@ void BroadCastSocketThread::execute() {
// Send this machine's host name and address in hostname:n.n.n.n format
sprintf(buff,"%s",myhostname);
for(unsigned int idx1 = 0; idx1 < ipList.size(); idx1++) {
sprintf(buff,"%s:%s",buff,ipList[idx1].c_str());
//sprintf(buff,"%s:%s",buff,ipList[idx1].c_str());
strcat(buff,":");
strcat(buff,ipList[idx1].c_str());
}
if(difftime(time(NULL),elapsed) >= 1 && getQuitStatus() == false) {
elapsed = time(NULL);
// Broadcast the packet to the subnet
//if( sendto( bcfd, buff, sizeof(buff) + 1, 0 , (struct sockaddr *)&bcaddr, sizeof(struct sockaddr_in) ) != sizeof(buff) + 1 )
if( sendto( bcfd[idx], buff, sizeof(buff) + 1, 0 , (struct sockaddr *)&bcLocal[idx], sizeof(struct sockaddr_in) ) != sizeof(buff) + 1 ) {
if( sendto( bcfd[idx], buff, buffMaxSize, 0 , (struct sockaddr *)&bcLocal[idx], sizeof(struct sockaddr_in) ) != buffMaxSize ) {
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"Sendto error: %s\n", getLastSocketErrorFormattedText().c_str());
}
else {