Skip to content

Commit

Permalink
fix warning: Null pointer argument in call to memory comparison function
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Yunlian Jiang authored and stephenhines committed Feb 9, 2017
1 parent 23f4e6b commit 33f6717
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions libsysutils/src/NetlinkEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down

0 comments on commit 33f6717

Please sign in to comment.