Fix Clang Static Analyser: Undefined allocation of 0 bytes

Unix API: Undefined allocation of 0 bytes (CERT MEM04-C; CWE-131): Call
to 'malloc' has an allocation size of 0 bytes
 1: Loop body executed 0 times in /home/phenom/GIT/RetroShare/trunk/
libbitdht/src/util/bdbloom.cc:223
 2: Calling 'bloomFilter::getFilter' in /home/phenom/GIT/RetroShare/
trunk/libbitdht/src/util/bdbloom.cc:240
 3: 'bytes' initialized to 0 in /home/phenom/GIT/RetroShare/trunk/
libbitdht/src/util/bdbloom.cc:141
 4: Call to 'malloc' has an allocation size of 0 bytes in /home/phenom/
GIT/RetroShare/trunk/libbitdht/src/util/bdbloom.cc:148
This commit is contained in:
Phenom 2017-04-19 11:50:24 +02:00 committed by csoler
parent f22dc0f0df
commit ff1908eda6

View File

@ -144,6 +144,11 @@ std::string bloomFilter::getFilter()
bytes++;
}
if (bytes==0)
{
std::cerr << "(EE) Error. Cannot allocate memory for 0 byte in " << __PRETTY_FUNCTION__ << std::endl;
return std::string();
}
// convert to binary array.
uint8_t *tmparray = (uint8_t *) malloc(bytes);