From ff1908eda6293d5105fbe1d60d5c41641e1bb0e8 Mon Sep 17 00:00:00 2001 From: Phenom Date: Wed, 19 Apr 2017 11:50:24 +0200 Subject: [PATCH] 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 --- libbitdht/src/util/bdbloom.cc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libbitdht/src/util/bdbloom.cc b/libbitdht/src/util/bdbloom.cc index 36f3a3bee..016808ea4 100644 --- a/libbitdht/src/util/bdbloom.cc +++ b/libbitdht/src/util/bdbloom.cc @@ -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);