summaryrefslogtreecommitdiff
path: root/test/Sema/warn-strlcpycat-size.c
diff options
context:
space:
mode:
Diffstat (limited to 'test/Sema/warn-strlcpycat-size.c')
-rw-r--r--test/Sema/warn-strlcpycat-size.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/test/Sema/warn-strlcpycat-size.c b/test/Sema/warn-strlcpycat-size.c
new file mode 100644
index 0000000000..e9e617488c
--- /dev/null
+++ b/test/Sema/warn-strlcpycat-size.c
@@ -0,0 +1,28 @@
+// RUN: %clang_cc1 -Wstrl-incorrect-size -verify -fsyntax-only %s
+
+typedef __SIZE_TYPE__ size_t;
+size_t strlcpy (char * restrict dst, const char * restrict src, size_t size);
+size_t strlcat (char * restrict dst, const char * restrict src, size_t size);
+size_t strlen (const char *s);
+
+char s1[100];
+char s2[200];
+char * s3;
+
+struct {
+ char f1[100];
+ char f2[100][3];
+} s4, **s5;
+
+int x;
+
+void f(void)
+{
+ strlcpy(s1, s2, sizeof(s1)); // no warning
+ strlcpy(s1, s2, sizeof(s2)); // expected-warning {{size argument in 'strlcpy' call appears to be size of the source; expected the size of the destination}} expected-note {{change size argument to be the size of the destination}}
+ strlcpy(s1, s3, strlen(s3)+1); // expected-warning {{size argument in 'strlcpy' call appears to be size of the source; expected the size of the destination}} expected-note {{change size argument to be the size of the destination}}
+ strlcat(s2, s3, sizeof(s3)); // expected-warning {{size argument in 'strlcat' call appears to be size of the source; expected the size of the destination}} expected-note {{change size argument to be the size of the destination}}
+ strlcpy(s4.f1, s2, sizeof(s2)); // expected-warning {{size argument in 'strlcpy' call appears to be size of the source; expected the size of the destination}} expected-note {{change size argument to be the size of the destination}}
+ strlcpy((*s5)->f2[x], s2, sizeof(s2)); // expected-warning {{size argument in 'strlcpy' call appears to be size of the source; expected the size of the destination}} expected-note {{change size argument to be the size of the destination}}
+ strlcpy(s1+3, s2, sizeof(s2)); // expected-warning {{size argument in 'strlcpy' call appears to be size of the source; expected the size of the destination}}
+}