diff options
| author | Nico Weber <nicolasweber@gmx.de> | 2011-10-13 22:30:23 +0000 |
|---|---|---|
| committer | Nico Weber <nicolasweber@gmx.de> | 2011-10-13 22:30:23 +0000 |
| commit | 39bfed8ad6bf365ab09163015fe85a650103f609 (patch) | |
| tree | 0ba82e3ea68c6593b2725886a53f4d2c5dce9667 /clang/test/SemaCXX/warn-memset-bad-sizeof.cpp | |
| parent | 834bd602e6343e16d6fd5505d6e1813f22d7d01c (diff) | |
| download | bcm5719-llvm-39bfed8ad6bf365ab09163015fe85a650103f609.tar.gz bcm5719-llvm-39bfed8ad6bf365ab09163015fe85a650103f609.zip | |
Extend -Wno-sizeof-array-argument to strncpy and friends.
This finds 2 bugs in chromium and 1 in hunspell, with 0 false positives.
llvm-svn: 141902
Diffstat (limited to 'clang/test/SemaCXX/warn-memset-bad-sizeof.cpp')
| -rw-r--r-- | clang/test/SemaCXX/warn-memset-bad-sizeof.cpp | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/clang/test/SemaCXX/warn-memset-bad-sizeof.cpp b/clang/test/SemaCXX/warn-memset-bad-sizeof.cpp index f4876ab442f..a018223cbda 100644 --- a/clang/test/SemaCXX/warn-memset-bad-sizeof.cpp +++ b/clang/test/SemaCXX/warn-memset-bad-sizeof.cpp @@ -112,3 +112,28 @@ void f(int* i) { memset(i, 0, sizeof(i)); } } + +extern "C" int strncmp(const char *s1, const char *s2, unsigned n); +extern "C" int strncasecmp(const char *s1, const char *s2, unsigned n); +extern "C" char *strncpy(char *det, const char *src, unsigned n); +extern "C" char *strncat(char *dst, const char *src, unsigned n); +extern "C" char *strndup(const char *src, unsigned n); + +void strcpy_and_friends() { + const char* FOO = "<- should be an array instead"; + const char* BAR = "<- this, too"; + + strncmp(FOO, BAR, sizeof(FOO)); // \ + // expected-warning {{argument to 'sizeof' in 'strncmp' call is the same expression as the destination}} + strncasecmp(FOO, BAR, sizeof(FOO)); // \ + // expected-warning {{argument to 'sizeof' in 'strncasecmp' call is the same expression as the destination}} + + char buff[80]; + + strncpy(buff, BAR, sizeof(BAR)); // \ + // expected-warning {{argument to 'sizeof' in 'strncpy' call is the same expression as the source}} + strncat(buff, BAR, sizeof(BAR)); // \ + // expected-warning {{argument to 'sizeof' in 'strncat' call is the same expression as the source}} + strndup(FOO, sizeof(FOO)); // \ + // expected-warning {{argument to 'sizeof' in 'strndup' call is the same expression as the source}} +} |

