fix warning: Null pointer argument in call to memory comparison function

This fixes  warning: Null pointer argument in call to
memory comparison function [clang-analyzer-cplusplus.NewDeleteLeaks]

Bug: None
Test: The warning is gone.
Change-Id: I957365184966cc1435d7e37d64f2cc6a32846ebd
This commit is contained in:
Yunlian Jiang 2017-02-07 15:39:25 -08:00 committed by Stephen Hines
parent 23f4e6b0a5
commit 33f671782a

View file

@ -561,10 +561,12 @@ bool NetlinkEvent::parseBinaryNetlinkMessage(char *buffer, int size) {
static const char*
has_prefix(const char* str, const char* end, const char* prefix, size_t prefixlen)
{
if ((end-str) >= (ptrdiff_t)prefixlen && !memcmp(str, prefix, prefixlen))
if ((end - str) >= (ptrdiff_t)prefixlen &&
(prefixlen == 0 || !memcmp(str, prefix, prefixlen))) {
return str + prefixlen;
else
} else {
return NULL;
}
}
/* Same as strlen(x) for constant string literals ONLY */