encoding: don't call memcmp() with null pointer
It's undefined behavior.
Change-Id: Id2fd5cbc0483af2bf9857e81fb6cac8163da3474
Refs: #4368
diff --git a/src/encoding/block.cpp b/src/encoding/block.cpp
index 13b10bc..691bbdf 100644
--- a/src/encoding/block.cpp
+++ b/src/encoding/block.cpp
@@ -28,6 +28,7 @@
#include <boost/asio/buffer.hpp>
#include <boost/range/adaptor/reversed.hpp>
+#include <cstring>
namespace ndn {
@@ -504,7 +505,8 @@
{
return lhs.type() == rhs.type() &&
lhs.value_size() == rhs.value_size() &&
- ::memcmp(lhs.value(), rhs.value(), lhs.value_size()) == 0;
+ (lhs.value_size() == 0 ||
+ std::memcmp(lhs.value(), rhs.value(), lhs.value_size()) == 0);
}
} // namespace ndn