Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,10 @@ ProgramStateRef CStringChecker::CheckOverlap(CheckerContext &C,

ProgramStateRef stateTrue, stateFalse;

if (!First.Expression->getType()->isAnyPointerType() ||
!Second.Expression->getType()->isAnyPointerType())
return state;

// Assume different address spaces cannot overlap.
if (First.Expression->getType()->getPointeeType().getAddressSpace() !=
Second.Expression->getType()->getPointeeType().getAddressSpace())
Expand Down
23 changes: 23 additions & 0 deletions clang/test/Analysis/buffer-overlap-decls.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// RUN: %clang_analyze_cc1 -verify %s -Wno-incompatible-library-redeclaration \
// RUN: -analyzer-checker=alpha.unix.cstring.BufferOverlap
// expected-no-diagnostics

typedef typeof(sizeof(int)) size_t;

void memcpy(int dst, int src, size_t size);

void test_memcpy_proxy() {
memcpy(42, 42, 42); // no-crash
}

void strcpy(int dst, char *src);

void test_strcpy_proxy() {
strcpy(42, (char *)42); // no-crash
}

void strxfrm(int dst, char *src, size_t size);

void test_strxfrm_proxy() {
strxfrm(42, (char *)42, 42); // no-crash
}
7 changes: 7 additions & 0 deletions clang/test/Analysis/buffer-overlap.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,10 @@ void test_snprintf6() {
char b[4] = {0};
snprintf(a, sizeof(a), "%s", b); // no-warning
}

void* memcpy(void* dest, const void* src, size_t count);

void test_memcpy_esoteric() {
label:
memcpy((char *)&&label, (const char *)memcpy, 1);
}