diff --git a/Source/core/ASN1.h b/Source/core/ASN1.h index 2d9a03318..c6b0fbff2 100644 --- a/Source/core/ASN1.h +++ b/Source/core/ASN1.h @@ -52,12 +52,10 @@ namespace Core { { if (_buffer != nullptr) { _buffer[0] = 1; -PUSH_WARNING(DISABLE_WARNING_CONSTANT_LOGICAL_OPERAND) _buffer[1] = (length & 0xFF); - _buffer[2] = ((length >> 8) && 0xFF); + _buffer[2] = ((length >> 8) & 0xFF); _buffer[3] = (length & 0xFF); - _buffer[4] = ((length >> 8) && 0xFF); -POP_WARNING() + _buffer[4] = ((length >> 8) & 0xFF); } } Buffer(const Buffer& copy) @@ -134,7 +132,7 @@ POP_WARNING() { if (_buffer != nullptr) { if (_buffer[0] == 1) { - delete _buffer; + delete[] _buffer; } else { _buffer[0] = _buffer[0] - 1; } diff --git a/Source/core/DataElement.h b/Source/core/DataElement.h index 10371da4f..65e2f7b63 100644 --- a/Source/core/DataElement.h +++ b/Source/core/DataElement.h @@ -953,7 +953,7 @@ POP_WARNING() inline uint64_t Size() const { - return (m_Offset - m_Buffer.Size()); + return (m_Buffer.Size() - m_Offset); } inline void SkipBytes(const unsigned int bytes) diff --git a/Source/core/DataElementFile.cpp b/Source/core/DataElementFile.cpp index e7734fd6c..4c19bd615 100644 --- a/Source/core/DataElementFile.cpp +++ b/Source/core/DataElementFile.cpp @@ -126,8 +126,9 @@ namespace Core { void* newBuffer = (::MapViewOfFile(m_MemoryMappedFile, flags, 0, 0, mapSize)); - // Seems like everything succeeded. Lets map it. - UpdateCache(0, static_cast(newBuffer), requiredSize, mapSize); + if (newBuffer != nullptr) { + UpdateCache(0, static_cast(newBuffer), requiredSize, mapSize); + } } } } @@ -166,7 +167,7 @@ namespace Core { } } - if (m_MemoryMappedFile == INVALID_HANDLE_VALUE) { + if (m_MemoryMappedFile != INVALID_HANDLE_VALUE) { DWORD flags = ((m_Flags & File::USER_READ) != 0 ? FILE_MAP_READ : 0) | ((m_Flags & File::USER_WRITE) != 0 ? FILE_MAP_WRITE : 0); void* newBuffer = ::MapViewOfFileEx(m_MemoryMappedFile, flags, 0, 0, static_cast(requestedSize), Buffer()); diff --git a/Source/core/FileSystem.h b/Source/core/FileSystem.h index f1c5c2a02..a5ffcb192 100644 --- a/Source/core/FileSystem.h +++ b/Source/core/FileSystem.h @@ -753,8 +753,6 @@ POP_WARNING() } void Reset() { - _dirFD = INVALID_HANDLE_VALUE; - if (_dirFD != INVALID_HANDLE_VALUE) { ::FindClose(_dirFD); _dirFD = INVALID_HANDLE_VALUE; diff --git a/Source/core/IPFrame.h b/Source/core/IPFrame.h index 713c8f785..2929d2f6c 100644 --- a/Source/core/IPFrame.h +++ b/Source/core/IPFrame.h @@ -71,7 +71,7 @@ namespace Core { return (&(_buffer[0])); } void DestinationMAC(const uint8_t MACAddress[]) { - memcpy(&(_buffer[0]), &MACAddress, MACSize); + memcpy(&(_buffer[0]), MACAddress, MACSize); } uint8_t* Frame() { return (SIZE > 0 ? &(_buffer[HeaderSize]) : nullptr); diff --git a/Source/core/Netlink.h b/Source/core/Netlink.h index a6b20dbeb..ad17af447 100644 --- a/Source/core/Netlink.h +++ b/Source/core/Netlink.h @@ -175,9 +175,9 @@ namespace Core { , _flags(move._flags) , _mySequence(move._mySequence) { - _type = NLMSG_DONE; - _flags = 0; - _mySequence = ~0; + move._type = NLMSG_DONE; + move._flags = 0; + move._mySequence = ~0; } virtual ~Netlink() = default; diff --git a/Source/core/NetworkInfo.cpp b/Source/core/NetworkInfo.cpp index 0f877b626..c4d50f69f 100644 --- a/Source/core/NetworkInfo.cpp +++ b/Source/core/NetworkInfo.cpp @@ -419,7 +419,7 @@ namespace Core { string result; PIP_ADAPTER_ADDRESSES info = LoadAdapterInfo(_index); - if (info->PhysicalAddressLength != 0) { + if ((info != nullptr) && (info->PhysicalAddressLength != 0)) { ConvertMACToString(info->PhysicalAddress, static_cast(info->PhysicalAddressLength), delimiter, result); } return (result); @@ -451,7 +451,7 @@ namespace Core { PIP_ADAPTER_ADDRESSES info = LoadAdapterInfo(_index); - if (info->PhysicalAddressLength != 0) { + if ((info != nullptr) && (info->PhysicalAddressLength != 0)) { ASSERT(length >= info->PhysicalAddressLength); ::memcpy(buffer, info->PhysicalAddress, info->PhysicalAddressLength); if (length > info->PhysicalAddressLength) { @@ -561,7 +561,7 @@ namespace Core { Adapters adapters; if (!getifaddrs(&interfaces)) { - struct ifaddrs* index = interfaces->ifa_next; + struct ifaddrs* index = interfaces; while (index != nullptr) { Adapters::iterator adapterIndex = adapters.find(index->ifa_name); @@ -583,6 +583,8 @@ namespace Core { addresses = index->second; } } + + freeifaddrs(interfaces); } return adapters.size(); } diff --git a/Source/core/RequestResponse.h b/Source/core/RequestResponse.h index 9b64d4eb1..9c78c9f5e 100644 --- a/Source/core/RequestResponse.h +++ b/Source/core/RequestResponse.h @@ -81,7 +81,7 @@ namespace Platform { public: inline RequestResponseState State() const { - return (m_Responded); + return (m_State); } inline REQUEST& Request() @@ -91,7 +91,7 @@ namespace Platform { inline RESPONSE& Response() { - return (*m_Request); + return (*m_Response); } private: diff --git a/Source/core/ResourceMonitor.h b/Source/core/ResourceMonitor.h index e0522e106..3e5c4a4fe 100644 --- a/Source/core/ResourceMonitor.h +++ b/Source/core/ResourceMonitor.h @@ -209,8 +209,12 @@ namespace Core { char procfn[64]; snprintf(procfn, sizeof(procfn), "/proc/self/fd/%d", info.descriptor); - size_t len = readlink(procfn, info.filename, sizeof(info.filename) - 1); - info.filename[len] = '\0'; + ssize_t len = readlink(procfn, info.filename, sizeof(info.filename) - 1); + if (len >= 0) { + info.filename[len] = '\0'; + } else { + info.filename[0] = '\0'; + } #endif #ifdef __WINDOWS__ info.monitor = 0; @@ -410,9 +414,11 @@ POP_WARNING() // Resize the array to fit.. _descriptorArray = static_cast<::pollfd*>(::malloc(sizeof(::pollfd) * _descriptorArrayLength)); - _descriptorArray[0].fd = _signalDescriptor; - _descriptorArray[0].events = POLLIN; - _descriptorArray[0].revents = 0; + if (_descriptorArray != nullptr) { + _descriptorArray[0].fd = _signalDescriptor; + _descriptorArray[0].events = POLLIN; + _descriptorArray[0].revents = 0; + } } int filledFileDescriptors = 1; diff --git a/Source/core/SerialPort.cpp b/Source/core/SerialPort.cpp index cd9566eb7..3d2b1fed5 100644 --- a/Source/core/SerialPort.cpp +++ b/Source/core/SerialPort.cpp @@ -934,8 +934,10 @@ void SerialPort::Read(const uint16_t readBytes) uint8_t* allocatedMemory = static_cast(::calloc(_sendBufferSize + _receiveBufferSize, 1)); - _sendBuffer = allocatedMemory; - _receiveBuffer = &(allocatedMemory[_sendBufferSize]); + if (allocatedMemory != nullptr) { + _sendBuffer = allocatedMemory; + _receiveBuffer = &(allocatedMemory[_sendBufferSize]); + } } diff --git a/Source/core/SocketPort.cpp b/Source/core/SocketPort.cpp index 30f1fe014..ca6219ce7 100644 --- a/Source/core/SocketPort.cpp +++ b/Source/core/SocketPort.cpp @@ -883,10 +883,12 @@ namespace Thunder { struct ifreq interface; #ifdef __APPLE__ strncpy(interface.ifr_name, specificInterface.c_str(), IFNAMSIZ - 1); + interface.ifr_name[IFNAMSIZ - 1] = '\0'; int index = if_nametoindex(interface.ifr_name); if (::setsockopt(l_Result, IPPROTO_IP, IP_BOUND_IF, (const char*)&index, sizeof(index)) < 0) { #else strncpy(interface.ifr_ifrn.ifrn_name, specificInterface.c_str(), IFNAMSIZ - 1); + interface.ifr_ifrn.ifrn_name[IFNAMSIZ - 1] = '\0'; if (::setsockopt(l_Result, SOL_SOCKET, SO_BINDTODEVICE, (const char*)&interface, sizeof(interface)) < 0) { #endif diff --git a/Source/core/SystemInfo.cpp b/Source/core/SystemInfo.cpp index ea88cb526..480ec4f14 100644 --- a/Source/core/SystemInfo.cpp +++ b/Source/core/SystemInfo.cpp @@ -147,7 +147,7 @@ namespace Core { #ifdef __APPLE__ m_uptime = 0; m_totalram = 0; - m_pageSize = 0; + m_pageSize = static_cast(sysconf(_SC_PAGESIZE)); m_freeram = 0; m_totalswap=0; m_freeswap=0; diff --git a/Source/core/WarningReportingControl.h b/Source/core/WarningReportingControl.h index bbdc9637a..133088546 100644 --- a/Source/core/WarningReportingControl.h +++ b/Source/core/WarningReportingControl.h @@ -165,7 +165,7 @@ namespace WarningReporting { } bool IsModuleExcluded(const string& module) const { - return _modules.find(module) != _callsigns.end(); + return _modules.find(module) != _modules.end(); } void InsertCallsign(const string& callsign) {