Skip to content

Commit 0d5c3da

Browse files
committed
small test and documentation fixes
1 parent 85e786c commit 0d5c3da

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

clang/docs/analyzer/checkers.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1914,7 +1914,7 @@ is missing.
19141914
.. code-block:: c
19151915
19161916
void test1() {
1917-
int l = strlen((char *)&test); // warn
1917+
int l = strlen((char *)&test1); // warn
19181918
}
19191919
19201920
void test2() {

clang/test/Analysis/string.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,8 @@ struct TestNotNullTerm {
5555
};
5656

5757
void test_notcstring_tempobject() {
58+
// FIXME: This warning from cstring.NotNullTerminated is a false positive.
59+
// Handling of similar cases is not perfect in other cstring checkers.
60+
// The fix would be a larger change in CStringChecker and affect multiple checkers.
5861
strlen((char[]){'a', 0}); // expected-warning{{Argument to string length function is a C++ temp object of type char[2], which is not a null-terminated string}}
5962
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// RUN: %clang_analyze_cc1 -verify %s -Wno-null-dereference \
2+
// RUN: -analyzer-checker=core \
3+
// RUN: -analyzer-checker=unix.cstring.NotNullTerminated \
4+
// RUN: -analyzer-checker=debug.ExprInspection
5+
6+
char *strcpy(char *restrict s1, const char *restrict s2);
7+
8+
void strcpy_fn(char *x) {
9+
strcpy(x, (char*)&strcpy_fn); // expected-warning{{Argument to string copy function is the address of the function 'strcpy_fn', which is not a null-terminated string}}
10+
}

0 commit comments

Comments
 (0)