mirror of
https://github.com/glest/glest-source.git
synced 2025-08-18 14:11:15 +02:00
- round #2 of coverity bug fixes
This commit is contained in:
@@ -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
|
||||
|
@@ -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);
|
||||
|
@@ -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) {
|
||||
|
@@ -260,6 +260,10 @@ string PlatformExceptionHandler::getStackTrace() {
|
||||
SymCleanup(hProcess);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef __MINGW32__
|
||||
delete [] pSym;
|
||||
#endif
|
||||
return result;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user