1cdc3a89d5de90b2299c56f4a46c3de590c5184d1Ted Kremenek// RUN: %clang_cc1 -analyze -analyzer-checker=core,unix.cstring,alpha.unix.cstring,debug.ExprInspection -analyzer-store=region -Wno-null-dereference -verify %s
2cdc3a89d5de90b2299c56f4a46c3de590c5184d1Ted Kremenek// RUN: %clang_cc1 -analyze -DUSE_BUILTINS -analyzer-checker=core,unix.cstring,alpha.unix.cstring,debug.ExprInspection -analyzer-store=region -Wno-null-dereference -verify %s
3cdc3a89d5de90b2299c56f4a46c3de590c5184d1Ted Kremenek// RUN: %clang_cc1 -analyze -DVARIANT -analyzer-checker=core,unix.cstring,alpha.unix.cstring,debug.ExprInspection -analyzer-store=region -Wno-null-dereference -verify %s
4cdc3a89d5de90b2299c56f4a46c3de590c5184d1Ted Kremenek// RUN: %clang_cc1 -analyze -DUSE_BUILTINS -DVARIANT -analyzer-checker=alpha.security.taint,core,unix.cstring,alpha.unix.cstring,debug.ExprInspection -analyzer-store=region -Wno-null-dereference -verify %s
519c5dd120e42b1ba0642309a185c70f4a41aadbdJordy Rose
619c5dd120e42b1ba0642309a185c70f4a41aadbdJordy Rose//===----------------------------------------------------------------------===
719c5dd120e42b1ba0642309a185c70f4a41aadbdJordy Rose// Declarations
819c5dd120e42b1ba0642309a185c70f4a41aadbdJordy Rose//===----------------------------------------------------------------------===
919c5dd120e42b1ba0642309a185c70f4a41aadbdJordy Rose
1019c5dd120e42b1ba0642309a185c70f4a41aadbdJordy Rose// Some functions are so similar to each other that they follow the same code
1119c5dd120e42b1ba0642309a185c70f4a41aadbdJordy Rose// path, such as memcpy and __memcpy_chk, or memcmp and bcmp. If VARIANT is
1219c5dd120e42b1ba0642309a185c70f4a41aadbdJordy Rose// defined, make sure to use the variants instead to make sure they are still
1319c5dd120e42b1ba0642309a185c70f4a41aadbdJordy Rose// checked by the analyzer.
1419c5dd120e42b1ba0642309a185c70f4a41aadbdJordy Rose
1519c5dd120e42b1ba0642309a185c70f4a41aadbdJordy Rose// Some functions are implemented as builtins. These should be #defined as
1619c5dd120e42b1ba0642309a185c70f4a41aadbdJordy Rose// BUILTIN(f), which will prepend "__builtin_" if USE_BUILTINS is defined.
1719c5dd120e42b1ba0642309a185c70f4a41aadbdJordy Rose
18fc8f0e14ad142ed811e90fbd9a30e419e301c717Chris Lattner// Functions that have variants and are also available as builtins should be
1919c5dd120e42b1ba0642309a185c70f4a41aadbdJordy Rose// declared carefully! See memcpy() for an example.
2019c5dd120e42b1ba0642309a185c70f4a41aadbdJordy Rose
2119c5dd120e42b1ba0642309a185c70f4a41aadbdJordy Rose#ifdef USE_BUILTINS
2219c5dd120e42b1ba0642309a185c70f4a41aadbdJordy Rose# define BUILTIN(f) __builtin_ ## f
2319c5dd120e42b1ba0642309a185c70f4a41aadbdJordy Rose#else /* USE_BUILTINS */
2419c5dd120e42b1ba0642309a185c70f4a41aadbdJordy Rose# define BUILTIN(f) f
2519c5dd120e42b1ba0642309a185c70f4a41aadbdJordy Rose#endif /* USE_BUILTINS */
2619c5dd120e42b1ba0642309a185c70f4a41aadbdJordy Rose
27e64f311c11a8751867c2538807054f4817c1f5cbJordy Rose#define NULL 0
2819c5dd120e42b1ba0642309a185c70f4a41aadbdJordy Rosetypedef typeof(sizeof(int)) size_t;
2943d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose
3043d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rosevoid clang_analyzer_eval(int);
3143d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose
32e3d250e488241cbfe71a592df4d07d03ad89434aAnna Zaksint scanf(const char *restrict format, ...);
3319c5dd120e42b1ba0642309a185c70f4a41aadbdJordy Rose
3419c5dd120e42b1ba0642309a185c70f4a41aadbdJordy Rose//===----------------------------------------------------------------------===
3519c5dd120e42b1ba0642309a185c70f4a41aadbdJordy Rose// strlen()
3619c5dd120e42b1ba0642309a185c70f4a41aadbdJordy Rose//===----------------------------------------------------------------------===
3719c5dd120e42b1ba0642309a185c70f4a41aadbdJordy Rose
3819c5dd120e42b1ba0642309a185c70f4a41aadbdJordy Rose#define strlen BUILTIN(strlen)
3919c5dd120e42b1ba0642309a185c70f4a41aadbdJordy Rosesize_t strlen(const char *s);
4019c5dd120e42b1ba0642309a185c70f4a41aadbdJordy Rose
4119c5dd120e42b1ba0642309a185c70f4a41aadbdJordy Rosevoid strlen_constant0() {
4243d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose  clang_analyzer_eval(strlen("123") == 3); // expected-warning{{TRUE}}
4319c5dd120e42b1ba0642309a185c70f4a41aadbdJordy Rose}
4419c5dd120e42b1ba0642309a185c70f4a41aadbdJordy Rose
4519c5dd120e42b1ba0642309a185c70f4a41aadbdJordy Rosevoid strlen_constant1() {
4619c5dd120e42b1ba0642309a185c70f4a41aadbdJordy Rose  const char *a = "123";
4743d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose  clang_analyzer_eval(strlen(a) == 3); // expected-warning{{TRUE}}
4819c5dd120e42b1ba0642309a185c70f4a41aadbdJordy Rose}
4919c5dd120e42b1ba0642309a185c70f4a41aadbdJordy Rose
5019c5dd120e42b1ba0642309a185c70f4a41aadbdJordy Rosevoid strlen_constant2(char x) {
5119c5dd120e42b1ba0642309a185c70f4a41aadbdJordy Rose  char a[] = "123";
5243d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose  clang_analyzer_eval(strlen(a) == 3); // expected-warning{{TRUE}}
5343d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose
5419c5dd120e42b1ba0642309a185c70f4a41aadbdJordy Rose  a[0] = x;
5543d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose  clang_analyzer_eval(strlen(a) == 3); // expected-warning{{UNKNOWN}}
5619c5dd120e42b1ba0642309a185c70f4a41aadbdJordy Rose}
5719c5dd120e42b1ba0642309a185c70f4a41aadbdJordy Rose
5819c5dd120e42b1ba0642309a185c70f4a41aadbdJordy Rosesize_t strlen_null() {
599e49d9fbdc861c25c2480233147dee07f5fa9660Jordy Rose  return strlen(0); // expected-warning{{Null pointer argument in call to string length function}}
6019c5dd120e42b1ba0642309a185c70f4a41aadbdJordy Rose}
6119c5dd120e42b1ba0642309a185c70f4a41aadbdJordy Rose
6219c5dd120e42b1ba0642309a185c70f4a41aadbdJordy Rosesize_t strlen_fn() {
639e49d9fbdc861c25c2480233147dee07f5fa9660Jordy Rose  return strlen((char*)&strlen_fn); // expected-warning{{Argument to string length function is the address of the function 'strlen_fn', which is not a null-terminated string}}
6419c5dd120e42b1ba0642309a185c70f4a41aadbdJordy Rose}
6519c5dd120e42b1ba0642309a185c70f4a41aadbdJordy Rose
6619c5dd120e42b1ba0642309a185c70f4a41aadbdJordy Rosesize_t strlen_nonloc() {
6719c5dd120e42b1ba0642309a185c70f4a41aadbdJordy Roselabel:
689e49d9fbdc861c25c2480233147dee07f5fa9660Jordy Rose  return strlen((char*)&&label); // expected-warning{{Argument to string length function is the address of the label 'label', which is not a null-terminated string}}
6919c5dd120e42b1ba0642309a185c70f4a41aadbdJordy Rose}
70a5261549754fab80e30e893d8fa706bfb31e430aJordy Rose
71a5261549754fab80e30e893d8fa706bfb31e430aJordy Rosevoid strlen_subregion() {
72e224ba7e3e604113aa160c379293bcb6425e8f36Carl Norum  struct two_strings { char a[2], b[2]; };
73a5261549754fab80e30e893d8fa706bfb31e430aJordy Rose  extern void use_two_strings(struct two_strings *);
74a5261549754fab80e30e893d8fa706bfb31e430aJordy Rose
75a5261549754fab80e30e893d8fa706bfb31e430aJordy Rose  struct two_strings z;
76a5261549754fab80e30e893d8fa706bfb31e430aJordy Rose  use_two_strings(&z);
77a5261549754fab80e30e893d8fa706bfb31e430aJordy Rose
78a5261549754fab80e30e893d8fa706bfb31e430aJordy Rose  size_t a = strlen(z.a);
79a5261549754fab80e30e893d8fa706bfb31e430aJordy Rose  z.b[0] = 5;
80a5261549754fab80e30e893d8fa706bfb31e430aJordy Rose  size_t b = strlen(z.a);
8143d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose  if (a == 0)
8243d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose    clang_analyzer_eval(b == 0); // expected-warning{{TRUE}}
83a5261549754fab80e30e893d8fa706bfb31e430aJordy Rose
84a5261549754fab80e30e893d8fa706bfb31e430aJordy Rose  use_two_strings(&z);
85a5261549754fab80e30e893d8fa706bfb31e430aJordy Rose
86a5261549754fab80e30e893d8fa706bfb31e430aJordy Rose  size_t c = strlen(z.a);
8743d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose  if (a == 0)
8843d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose    clang_analyzer_eval(c == 0); // expected-warning{{UNKNOWN}}
89a5261549754fab80e30e893d8fa706bfb31e430aJordy Rose}
90a5261549754fab80e30e893d8fa706bfb31e430aJordy Rose
91a5261549754fab80e30e893d8fa706bfb31e430aJordy Roseextern void use_string(char *);
92a5261549754fab80e30e893d8fa706bfb31e430aJordy Rosevoid strlen_argument(char *x) {
93a5261549754fab80e30e893d8fa706bfb31e430aJordy Rose  size_t a = strlen(x);
94a5261549754fab80e30e893d8fa706bfb31e430aJordy Rose  size_t b = strlen(x);
9543d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose  if (a == 0)
9643d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose    clang_analyzer_eval(b == 0); // expected-warning{{TRUE}}
97a5261549754fab80e30e893d8fa706bfb31e430aJordy Rose
98a5261549754fab80e30e893d8fa706bfb31e430aJordy Rose  use_string(x);
99a5261549754fab80e30e893d8fa706bfb31e430aJordy Rose
100a5261549754fab80e30e893d8fa706bfb31e430aJordy Rose  size_t c = strlen(x);
10143d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose  if (a == 0)
10243d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose    clang_analyzer_eval(c == 0); // expected-warning{{UNKNOWN}}
103a5261549754fab80e30e893d8fa706bfb31e430aJordy Rose}
104a5261549754fab80e30e893d8fa706bfb31e430aJordy Rose
105a5261549754fab80e30e893d8fa706bfb31e430aJordy Roseextern char global_str[];
106a5261549754fab80e30e893d8fa706bfb31e430aJordy Rosevoid strlen_global() {
107a5261549754fab80e30e893d8fa706bfb31e430aJordy Rose  size_t a = strlen(global_str);
108a5261549754fab80e30e893d8fa706bfb31e430aJordy Rose  size_t b = strlen(global_str);
10943d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose  if (a == 0) {
11043d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose    clang_analyzer_eval(b == 0); // expected-warning{{TRUE}}
11143d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose    // Make sure clang_analyzer_eval does not invalidate globals.
11243d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose    clang_analyzer_eval(strlen(global_str) == 0); // expected-warning{{TRUE}}
11343d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose  }
114a5261549754fab80e30e893d8fa706bfb31e430aJordy Rose
115a5261549754fab80e30e893d8fa706bfb31e430aJordy Rose  // Call a function with unknown effects, which should invalidate globals.
116a5261549754fab80e30e893d8fa706bfb31e430aJordy Rose  use_string(0);
117a5261549754fab80e30e893d8fa706bfb31e430aJordy Rose
118a5261549754fab80e30e893d8fa706bfb31e430aJordy Rose  size_t c = strlen(global_str);
11943d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose  if (a == 0)
12043d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose    clang_analyzer_eval(c == 0); // expected-warning{{UNKNOWN}}
121a5261549754fab80e30e893d8fa706bfb31e430aJordy Rose}
122a5261549754fab80e30e893d8fa706bfb31e430aJordy Rose
123a5261549754fab80e30e893d8fa706bfb31e430aJordy Rosevoid strlen_indirect(char *x) {
124a5261549754fab80e30e893d8fa706bfb31e430aJordy Rose  size_t a = strlen(x);
125a5261549754fab80e30e893d8fa706bfb31e430aJordy Rose  char *p = x;
126a5261549754fab80e30e893d8fa706bfb31e430aJordy Rose  char **p2 = &p;
127a5261549754fab80e30e893d8fa706bfb31e430aJordy Rose  size_t b = strlen(x);
12843d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose  if (a == 0)
12943d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose    clang_analyzer_eval(b == 0); // expected-warning{{TRUE}}
130a5261549754fab80e30e893d8fa706bfb31e430aJordy Rose
131a5261549754fab80e30e893d8fa706bfb31e430aJordy Rose  extern void use_string_ptr(char*const*);
132a5261549754fab80e30e893d8fa706bfb31e430aJordy Rose  use_string_ptr(p2);
133a5261549754fab80e30e893d8fa706bfb31e430aJordy Rose
134a5261549754fab80e30e893d8fa706bfb31e430aJordy Rose  size_t c = strlen(x);
13543d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose  if (a == 0)
13643d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose    clang_analyzer_eval(c == 0); // expected-warning{{UNKNOWN}}
137a5261549754fab80e30e893d8fa706bfb31e430aJordy Rose}
138a5261549754fab80e30e893d8fa706bfb31e430aJordy Rose
1392cbe791d3e9b26f30196c4852da75d9ad67b4ad9Anna Zaksvoid strlen_indirect2(char *x) {
1402cbe791d3e9b26f30196c4852da75d9ad67b4ad9Anna Zaks  size_t a = strlen(x);
1412cbe791d3e9b26f30196c4852da75d9ad67b4ad9Anna Zaks  char *p = x;
1422cbe791d3e9b26f30196c4852da75d9ad67b4ad9Anna Zaks  char **p2 = &p;
1432cbe791d3e9b26f30196c4852da75d9ad67b4ad9Anna Zaks  extern void use_string_ptr2(char**);
1442cbe791d3e9b26f30196c4852da75d9ad67b4ad9Anna Zaks  use_string_ptr2(p2);
1452cbe791d3e9b26f30196c4852da75d9ad67b4ad9Anna Zaks
1462cbe791d3e9b26f30196c4852da75d9ad67b4ad9Anna Zaks  size_t c = strlen(x);
14743d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose  if (a == 0)
14843d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose    clang_analyzer_eval(c == 0); // expected-warning{{UNKNOWN}}
1492cbe791d3e9b26f30196c4852da75d9ad67b4ad9Anna Zaks}
1502cbe791d3e9b26f30196c4852da75d9ad67b4ad9Anna Zaks
151a5261549754fab80e30e893d8fa706bfb31e430aJordy Rosevoid strlen_liveness(const char *x) {
152a5261549754fab80e30e893d8fa706bfb31e430aJordy Rose  if (strlen(x) < 5)
153a5261549754fab80e30e893d8fa706bfb31e430aJordy Rose    return;
15443d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose  clang_analyzer_eval(strlen(x) < 5); // expected-warning{{FALSE}}
155a5261549754fab80e30e893d8fa706bfb31e430aJordy Rose}
156e64f311c11a8751867c2538807054f4817c1f5cbJordy Rose
157e64f311c11a8751867c2538807054f4817c1f5cbJordy Rose//===----------------------------------------------------------------------===
158be4242ce039f0542ea0dd5f234aa0ee698f90c53Ted Kremenek// strnlen()
159be4242ce039f0542ea0dd5f234aa0ee698f90c53Ted Kremenek//===----------------------------------------------------------------------===
160be4242ce039f0542ea0dd5f234aa0ee698f90c53Ted Kremenek
161be4242ce039f0542ea0dd5f234aa0ee698f90c53Ted Kremeneksize_t strnlen(const char *s, size_t maxlen);
162be4242ce039f0542ea0dd5f234aa0ee698f90c53Ted Kremenek
163be4242ce039f0542ea0dd5f234aa0ee698f90c53Ted Kremenekvoid strnlen_constant0() {
16443d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose  clang_analyzer_eval(strnlen("123", 10) == 3); // expected-warning{{TRUE}}
165be4242ce039f0542ea0dd5f234aa0ee698f90c53Ted Kremenek}
166be4242ce039f0542ea0dd5f234aa0ee698f90c53Ted Kremenek
167be4242ce039f0542ea0dd5f234aa0ee698f90c53Ted Kremenekvoid strnlen_constant1() {
168be4242ce039f0542ea0dd5f234aa0ee698f90c53Ted Kremenek  const char *a = "123";
16943d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose  clang_analyzer_eval(strnlen(a, 10) == 3); // expected-warning{{TRUE}}
170be4242ce039f0542ea0dd5f234aa0ee698f90c53Ted Kremenek}
171be4242ce039f0542ea0dd5f234aa0ee698f90c53Ted Kremenek
172be4242ce039f0542ea0dd5f234aa0ee698f90c53Ted Kremenekvoid strnlen_constant2(char x) {
173be4242ce039f0542ea0dd5f234aa0ee698f90c53Ted Kremenek  char a[] = "123";
17443d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose  clang_analyzer_eval(strnlen(a, 10) == 3); // expected-warning{{TRUE}}
175be4242ce039f0542ea0dd5f234aa0ee698f90c53Ted Kremenek  a[0] = x;
17643d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose  clang_analyzer_eval(strnlen(a, 10) == 3); // expected-warning{{UNKNOWN}}
177be4242ce039f0542ea0dd5f234aa0ee698f90c53Ted Kremenek}
178be4242ce039f0542ea0dd5f234aa0ee698f90c53Ted Kremenek
179be4242ce039f0542ea0dd5f234aa0ee698f90c53Ted Kremenekvoid strnlen_constant4() {
18043d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose  clang_analyzer_eval(strnlen("123456", 3) == 3); // expected-warning{{TRUE}}
181be4242ce039f0542ea0dd5f234aa0ee698f90c53Ted Kremenek}
182be4242ce039f0542ea0dd5f234aa0ee698f90c53Ted Kremenek
183be4242ce039f0542ea0dd5f234aa0ee698f90c53Ted Kremenekvoid strnlen_constant5() {
184be4242ce039f0542ea0dd5f234aa0ee698f90c53Ted Kremenek  const char *a = "123456";
18543d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose  clang_analyzer_eval(strnlen(a, 3) == 3); // expected-warning{{TRUE}}
186be4242ce039f0542ea0dd5f234aa0ee698f90c53Ted Kremenek}
187be4242ce039f0542ea0dd5f234aa0ee698f90c53Ted Kremenek
188be4242ce039f0542ea0dd5f234aa0ee698f90c53Ted Kremenekvoid strnlen_constant6(char x) {
189be4242ce039f0542ea0dd5f234aa0ee698f90c53Ted Kremenek  char a[] = "123456";
19043d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose  clang_analyzer_eval(strnlen(a, 3) == 3); // expected-warning{{TRUE}}
191be4242ce039f0542ea0dd5f234aa0ee698f90c53Ted Kremenek  a[0] = x;
19243d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose  clang_analyzer_eval(strnlen(a, 3) == 3); // expected-warning{{UNKNOWN}}
193be4242ce039f0542ea0dd5f234aa0ee698f90c53Ted Kremenek}
194be4242ce039f0542ea0dd5f234aa0ee698f90c53Ted Kremenek
195be4242ce039f0542ea0dd5f234aa0ee698f90c53Ted Kremeneksize_t strnlen_null() {
1969e49d9fbdc861c25c2480233147dee07f5fa9660Jordy Rose  return strnlen(0, 3); // expected-warning{{Null pointer argument in call to string length function}}
197be4242ce039f0542ea0dd5f234aa0ee698f90c53Ted Kremenek}
198be4242ce039f0542ea0dd5f234aa0ee698f90c53Ted Kremenek
199be4242ce039f0542ea0dd5f234aa0ee698f90c53Ted Kremeneksize_t strnlen_fn() {
2009e49d9fbdc861c25c2480233147dee07f5fa9660Jordy Rose  return strnlen((char*)&strlen_fn, 3); // expected-warning{{Argument to string length function is the address of the function 'strlen_fn', which is not a null-terminated string}}
201be4242ce039f0542ea0dd5f234aa0ee698f90c53Ted Kremenek}
202be4242ce039f0542ea0dd5f234aa0ee698f90c53Ted Kremenek
203be4242ce039f0542ea0dd5f234aa0ee698f90c53Ted Kremeneksize_t strnlen_nonloc() {
204be4242ce039f0542ea0dd5f234aa0ee698f90c53Ted Kremeneklabel:
2059e49d9fbdc861c25c2480233147dee07f5fa9660Jordy Rose  return strnlen((char*)&&label, 3); // expected-warning{{Argument to string length function is the address of the label 'label', which is not a null-terminated string}}
206be4242ce039f0542ea0dd5f234aa0ee698f90c53Ted Kremenek}
207be4242ce039f0542ea0dd5f234aa0ee698f90c53Ted Kremenek
208793bff3fb7ca2a31e81aa7f4f3f21f921459010bJordy Rosevoid strnlen_zero() {
20943d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose  clang_analyzer_eval(strnlen("abc", 0) == 0); // expected-warning{{TRUE}}
21043d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose  clang_analyzer_eval(strnlen(NULL, 0) == 0); // expected-warning{{TRUE}}
211793bff3fb7ca2a31e81aa7f4f3f21f921459010bJordy Rose}
212be4242ce039f0542ea0dd5f234aa0ee698f90c53Ted Kremenek
213793bff3fb7ca2a31e81aa7f4f3f21f921459010bJordy Rosesize_t strnlen_compound_literal() {
214793bff3fb7ca2a31e81aa7f4f3f21f921459010bJordy Rose  // This used to crash because we don't model the string lengths of
215793bff3fb7ca2a31e81aa7f4f3f21f921459010bJordy Rose  // compound literals.
216793bff3fb7ca2a31e81aa7f4f3f21f921459010bJordy Rose  return strnlen((char[]) { 'a', 'b', 0 }, 1);
217793bff3fb7ca2a31e81aa7f4f3f21f921459010bJordy Rose}
218be4242ce039f0542ea0dd5f234aa0ee698f90c53Ted Kremenek
219793bff3fb7ca2a31e81aa7f4f3f21f921459010bJordy Rosesize_t strnlen_unknown_limit(float f) {
220793bff3fb7ca2a31e81aa7f4f3f21f921459010bJordy Rose  // This used to crash because we don't model the integer values of floats.
221793bff3fb7ca2a31e81aa7f4f3f21f921459010bJordy Rose  return strnlen("abc", (int)f);
222793bff3fb7ca2a31e81aa7f4f3f21f921459010bJordy Rose}
223be4242ce039f0542ea0dd5f234aa0ee698f90c53Ted Kremenek
224793bff3fb7ca2a31e81aa7f4f3f21f921459010bJordy Rosevoid strnlen_is_not_strlen(char *x) {
22543d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose  clang_analyzer_eval(strnlen(x, 10) == strlen(x)); // expected-warning{{UNKNOWN}}
226be4242ce039f0542ea0dd5f234aa0ee698f90c53Ted Kremenek}
227be4242ce039f0542ea0dd5f234aa0ee698f90c53Ted Kremenek
228793bff3fb7ca2a31e81aa7f4f3f21f921459010bJordy Rosevoid strnlen_at_limit(char *x) {
229793bff3fb7ca2a31e81aa7f4f3f21f921459010bJordy Rose  size_t len = strnlen(x, 10);
23043d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose  clang_analyzer_eval(len <= 10); // expected-warning{{TRUE}}
23143d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose  clang_analyzer_eval(len == 10); // expected-warning{{UNKNOWN}}
23243d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose  clang_analyzer_eval(len < 10); // expected-warning{{UNKNOWN}}
233be4242ce039f0542ea0dd5f234aa0ee698f90c53Ted Kremenek}
234be4242ce039f0542ea0dd5f234aa0ee698f90c53Ted Kremenek
235793bff3fb7ca2a31e81aa7f4f3f21f921459010bJordy Rosevoid strnlen_at_actual(size_t limit) {
236793bff3fb7ca2a31e81aa7f4f3f21f921459010bJordy Rose  size_t len = strnlen("abc", limit);
23743d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose  clang_analyzer_eval(len <= 3); // expected-warning{{TRUE}}
23843d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose  // This is due to eager assertion in strnlen.
23943d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose  if (limit == 0) {
24043d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose    clang_analyzer_eval(len == 0); // expected-warning{{TRUE}}
24143d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose  } else {
24243d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose    clang_analyzer_eval(len == 3); // expected-warning{{UNKNOWN}}
24343d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose    clang_analyzer_eval(len < 3); // expected-warning{{UNKNOWN}}
24443d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose  }
245be4242ce039f0542ea0dd5f234aa0ee698f90c53Ted Kremenek}
246be4242ce039f0542ea0dd5f234aa0ee698f90c53Ted Kremenek
247be4242ce039f0542ea0dd5f234aa0ee698f90c53Ted Kremenek//===----------------------------------------------------------------------===
248e64f311c11a8751867c2538807054f4817c1f5cbJordy Rose// strcpy()
249e64f311c11a8751867c2538807054f4817c1f5cbJordy Rose//===----------------------------------------------------------------------===
250e64f311c11a8751867c2538807054f4817c1f5cbJordy Rose
251e64f311c11a8751867c2538807054f4817c1f5cbJordy Rose#ifdef VARIANT
252e64f311c11a8751867c2538807054f4817c1f5cbJordy Rose
253e64f311c11a8751867c2538807054f4817c1f5cbJordy Rose#define __strcpy_chk BUILTIN(__strcpy_chk)
254e64f311c11a8751867c2538807054f4817c1f5cbJordy Rosechar *__strcpy_chk(char *restrict s1, const char *restrict s2, size_t destlen);
255e64f311c11a8751867c2538807054f4817c1f5cbJordy Rose
256e64f311c11a8751867c2538807054f4817c1f5cbJordy Rose#define strcpy(a,b) __strcpy_chk(a,b,(size_t)-1)
257e64f311c11a8751867c2538807054f4817c1f5cbJordy Rose
258e64f311c11a8751867c2538807054f4817c1f5cbJordy Rose#else /* VARIANT */
259e64f311c11a8751867c2538807054f4817c1f5cbJordy Rose
260e64f311c11a8751867c2538807054f4817c1f5cbJordy Rose#define strcpy BUILTIN(strcpy)
261e64f311c11a8751867c2538807054f4817c1f5cbJordy Rosechar *strcpy(char *restrict s1, const char *restrict s2);
262e64f311c11a8751867c2538807054f4817c1f5cbJordy Rose
263e64f311c11a8751867c2538807054f4817c1f5cbJordy Rose#endif /* VARIANT */
264e64f311c11a8751867c2538807054f4817c1f5cbJordy Rose
265e64f311c11a8751867c2538807054f4817c1f5cbJordy Rose
266e64f311c11a8751867c2538807054f4817c1f5cbJordy Rosevoid strcpy_null_dst(char *x) {
2679e49d9fbdc861c25c2480233147dee07f5fa9660Jordy Rose  strcpy(NULL, x); // expected-warning{{Null pointer argument in call to string copy function}}
268e64f311c11a8751867c2538807054f4817c1f5cbJordy Rose}
269e64f311c11a8751867c2538807054f4817c1f5cbJordy Rose
270e64f311c11a8751867c2538807054f4817c1f5cbJordy Rosevoid strcpy_null_src(char *x) {
2719e49d9fbdc861c25c2480233147dee07f5fa9660Jordy Rose  strcpy(x, NULL); // expected-warning{{Null pointer argument in call to string copy function}}
272e64f311c11a8751867c2538807054f4817c1f5cbJordy Rose}
273e64f311c11a8751867c2538807054f4817c1f5cbJordy Rose
274e64f311c11a8751867c2538807054f4817c1f5cbJordy Rosevoid strcpy_fn(char *x) {
2759e49d9fbdc861c25c2480233147dee07f5fa9660Jordy Rose  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}}
276e64f311c11a8751867c2538807054f4817c1f5cbJordy Rose}
277e64f311c11a8751867c2538807054f4817c1f5cbJordy Rose
278ce8ef16b1c58a304b7b59fad9836ad32d6ed020cAnna Zaksvoid strcpy_fn_const(char *x) {
279ce8ef16b1c58a304b7b59fad9836ad32d6ed020cAnna Zaks  strcpy(x, (const 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}}
280ce8ef16b1c58a304b7b59fad9836ad32d6ed020cAnna Zaks}
281ce8ef16b1c58a304b7b59fad9836ad32d6ed020cAnna Zaks
282e64f311c11a8751867c2538807054f4817c1f5cbJordy Rosevoid strcpy_effects(char *x, char *y) {
283e64f311c11a8751867c2538807054f4817c1f5cbJordy Rose  char a = x[0];
284e64f311c11a8751867c2538807054f4817c1f5cbJordy Rose
28543d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose  clang_analyzer_eval(strcpy(x, y) == x); // expected-warning{{TRUE}}
28643d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose  clang_analyzer_eval(strlen(x) == strlen(y)); // expected-warning{{TRUE}}
28743d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose  clang_analyzer_eval(a == x[0]); // expected-warning{{UNKNOWN}}
288e64f311c11a8751867c2538807054f4817c1f5cbJordy Rose}
289e64f311c11a8751867c2538807054f4817c1f5cbJordy Rose
290e64f311c11a8751867c2538807054f4817c1f5cbJordy Rosevoid strcpy_overflow(char *y) {
291e64f311c11a8751867c2538807054f4817c1f5cbJordy Rose  char x[4];
292e64f311c11a8751867c2538807054f4817c1f5cbJordy Rose  if (strlen(y) == 4)
2939e49d9fbdc861c25c2480233147dee07f5fa9660Jordy Rose    strcpy(x, y); // expected-warning{{String copy function overflows destination buffer}}
294e64f311c11a8751867c2538807054f4817c1f5cbJordy Rose}
295e64f311c11a8751867c2538807054f4817c1f5cbJordy Rose
296e64f311c11a8751867c2538807054f4817c1f5cbJordy Rosevoid strcpy_no_overflow(char *y) {
297e64f311c11a8751867c2538807054f4817c1f5cbJordy Rose  char x[4];
298e64f311c11a8751867c2538807054f4817c1f5cbJordy Rose  if (strlen(y) == 3)
299e64f311c11a8751867c2538807054f4817c1f5cbJordy Rose    strcpy(x, y); // no-warning
300e64f311c11a8751867c2538807054f4817c1f5cbJordy Rose}
301e64f311c11a8751867c2538807054f4817c1f5cbJordy Rose
302e64f311c11a8751867c2538807054f4817c1f5cbJordy Rose//===----------------------------------------------------------------------===
303e64f311c11a8751867c2538807054f4817c1f5cbJordy Rose// stpcpy()
304e64f311c11a8751867c2538807054f4817c1f5cbJordy Rose//===----------------------------------------------------------------------===
305e64f311c11a8751867c2538807054f4817c1f5cbJordy Rose
306e64f311c11a8751867c2538807054f4817c1f5cbJordy Rose#ifdef VARIANT
307e64f311c11a8751867c2538807054f4817c1f5cbJordy Rose
308e64f311c11a8751867c2538807054f4817c1f5cbJordy Rose#define __stpcpy_chk BUILTIN(__stpcpy_chk)
309e64f311c11a8751867c2538807054f4817c1f5cbJordy Rosechar *__stpcpy_chk(char *restrict s1, const char *restrict s2, size_t destlen);
310e64f311c11a8751867c2538807054f4817c1f5cbJordy Rose
311e64f311c11a8751867c2538807054f4817c1f5cbJordy Rose#define stpcpy(a,b) __stpcpy_chk(a,b,(size_t)-1)
312e64f311c11a8751867c2538807054f4817c1f5cbJordy Rose
313e64f311c11a8751867c2538807054f4817c1f5cbJordy Rose#else /* VARIANT */
314e64f311c11a8751867c2538807054f4817c1f5cbJordy Rose
315e64f311c11a8751867c2538807054f4817c1f5cbJordy Rose#define stpcpy BUILTIN(stpcpy)
316e64f311c11a8751867c2538807054f4817c1f5cbJordy Rosechar *stpcpy(char *restrict s1, const char *restrict s2);
317e64f311c11a8751867c2538807054f4817c1f5cbJordy Rose
318e64f311c11a8751867c2538807054f4817c1f5cbJordy Rose#endif /* VARIANT */
319e64f311c11a8751867c2538807054f4817c1f5cbJordy Rose
320e64f311c11a8751867c2538807054f4817c1f5cbJordy Rose
321e64f311c11a8751867c2538807054f4817c1f5cbJordy Rosevoid stpcpy_effect(char *x, char *y) {
322e64f311c11a8751867c2538807054f4817c1f5cbJordy Rose  char a = x[0];
323e64f311c11a8751867c2538807054f4817c1f5cbJordy Rose
32443d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose  clang_analyzer_eval(stpcpy(x, y) == &x[strlen(y)]); // expected-warning{{TRUE}}
32543d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose  clang_analyzer_eval(strlen(x) == strlen(y)); // expected-warning{{TRUE}}
32643d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose  clang_analyzer_eval(a == x[0]); // expected-warning{{UNKNOWN}}
327e64f311c11a8751867c2538807054f4817c1f5cbJordy Rose}
328e64f311c11a8751867c2538807054f4817c1f5cbJordy Rose
329e64f311c11a8751867c2538807054f4817c1f5cbJordy Rosevoid stpcpy_overflow(char *y) {
330e64f311c11a8751867c2538807054f4817c1f5cbJordy Rose  char x[4];
331e64f311c11a8751867c2538807054f4817c1f5cbJordy Rose  if (strlen(y) == 4)
3329e49d9fbdc861c25c2480233147dee07f5fa9660Jordy Rose    stpcpy(x, y); // expected-warning{{String copy function overflows destination buffer}}
333e64f311c11a8751867c2538807054f4817c1f5cbJordy Rose}
334e64f311c11a8751867c2538807054f4817c1f5cbJordy Rose
335e64f311c11a8751867c2538807054f4817c1f5cbJordy Rosevoid stpcpy_no_overflow(char *y) {
336e64f311c11a8751867c2538807054f4817c1f5cbJordy Rose  char x[4];
337e64f311c11a8751867c2538807054f4817c1f5cbJordy Rose  if (strlen(y) == 3)
338e64f311c11a8751867c2538807054f4817c1f5cbJordy Rose    stpcpy(x, y); // no-warning
339e64f311c11a8751867c2538807054f4817c1f5cbJordy Rose}
340067bbd0e11c71a33b51832532e836971be697699Lenny Maiorani
341067bbd0e11c71a33b51832532e836971be697699Lenny Maiorani//===----------------------------------------------------------------------===
342067bbd0e11c71a33b51832532e836971be697699Lenny Maiorani// strcat()
343067bbd0e11c71a33b51832532e836971be697699Lenny Maiorani//===----------------------------------------------------------------------===
344067bbd0e11c71a33b51832532e836971be697699Lenny Maiorani
345067bbd0e11c71a33b51832532e836971be697699Lenny Maiorani#ifdef VARIANT
346067bbd0e11c71a33b51832532e836971be697699Lenny Maiorani
347067bbd0e11c71a33b51832532e836971be697699Lenny Maiorani#define __strcat_chk BUILTIN(__strcat_chk)
348067bbd0e11c71a33b51832532e836971be697699Lenny Maioranichar *__strcat_chk(char *restrict s1, const char *restrict s2, size_t destlen);
349067bbd0e11c71a33b51832532e836971be697699Lenny Maiorani
350067bbd0e11c71a33b51832532e836971be697699Lenny Maiorani#define strcat(a,b) __strcat_chk(a,b,(size_t)-1)
351067bbd0e11c71a33b51832532e836971be697699Lenny Maiorani
352067bbd0e11c71a33b51832532e836971be697699Lenny Maiorani#else /* VARIANT */
353067bbd0e11c71a33b51832532e836971be697699Lenny Maiorani
354067bbd0e11c71a33b51832532e836971be697699Lenny Maiorani#define strcat BUILTIN(strcat)
355067bbd0e11c71a33b51832532e836971be697699Lenny Maioranichar *strcat(char *restrict s1, const char *restrict s2);
356067bbd0e11c71a33b51832532e836971be697699Lenny Maiorani
357067bbd0e11c71a33b51832532e836971be697699Lenny Maiorani#endif /* VARIANT */
358067bbd0e11c71a33b51832532e836971be697699Lenny Maiorani
359067bbd0e11c71a33b51832532e836971be697699Lenny Maiorani
360067bbd0e11c71a33b51832532e836971be697699Lenny Maioranivoid strcat_null_dst(char *x) {
3619e49d9fbdc861c25c2480233147dee07f5fa9660Jordy Rose  strcat(NULL, x); // expected-warning{{Null pointer argument in call to string copy function}}
362067bbd0e11c71a33b51832532e836971be697699Lenny Maiorani}
363067bbd0e11c71a33b51832532e836971be697699Lenny Maiorani
364067bbd0e11c71a33b51832532e836971be697699Lenny Maioranivoid strcat_null_src(char *x) {
3659e49d9fbdc861c25c2480233147dee07f5fa9660Jordy Rose  strcat(x, NULL); // expected-warning{{Null pointer argument in call to string copy function}}
366067bbd0e11c71a33b51832532e836971be697699Lenny Maiorani}
367067bbd0e11c71a33b51832532e836971be697699Lenny Maiorani
368067bbd0e11c71a33b51832532e836971be697699Lenny Maioranivoid strcat_fn(char *x) {
3699e49d9fbdc861c25c2480233147dee07f5fa9660Jordy Rose  strcat(x, (char*)&strcat_fn); // expected-warning{{Argument to string copy function is the address of the function 'strcat_fn', which is not a null-terminated string}}
370067bbd0e11c71a33b51832532e836971be697699Lenny Maiorani}
371067bbd0e11c71a33b51832532e836971be697699Lenny Maiorani
372067bbd0e11c71a33b51832532e836971be697699Lenny Maioranivoid strcat_effects(char *y) {
373067bbd0e11c71a33b51832532e836971be697699Lenny Maiorani  char x[8] = "123";
374067bbd0e11c71a33b51832532e836971be697699Lenny Maiorani  size_t orig_len = strlen(x);
375067bbd0e11c71a33b51832532e836971be697699Lenny Maiorani  char a = x[0];
376067bbd0e11c71a33b51832532e836971be697699Lenny Maiorani
377067bbd0e11c71a33b51832532e836971be697699Lenny Maiorani  if (strlen(y) != 4)
378067bbd0e11c71a33b51832532e836971be697699Lenny Maiorani    return;
379067bbd0e11c71a33b51832532e836971be697699Lenny Maiorani
38043d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose  clang_analyzer_eval(strcat(x, y) == x); // expected-warning{{TRUE}}
38143d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose  clang_analyzer_eval((int)strlen(x) == (orig_len + strlen(y))); // expected-warning{{TRUE}}
382067bbd0e11c71a33b51832532e836971be697699Lenny Maiorani}
383067bbd0e11c71a33b51832532e836971be697699Lenny Maiorani
384067bbd0e11c71a33b51832532e836971be697699Lenny Maioranivoid strcat_overflow_0(char *y) {
385067bbd0e11c71a33b51832532e836971be697699Lenny Maiorani  char x[4] = "12";
386067bbd0e11c71a33b51832532e836971be697699Lenny Maiorani  if (strlen(y) == 4)
3879e49d9fbdc861c25c2480233147dee07f5fa9660Jordy Rose    strcat(x, y); // expected-warning{{String copy function overflows destination buffer}}
388067bbd0e11c71a33b51832532e836971be697699Lenny Maiorani}
389067bbd0e11c71a33b51832532e836971be697699Lenny Maiorani
390067bbd0e11c71a33b51832532e836971be697699Lenny Maioranivoid strcat_overflow_1(char *y) {
391067bbd0e11c71a33b51832532e836971be697699Lenny Maiorani  char x[4] = "12";
392067bbd0e11c71a33b51832532e836971be697699Lenny Maiorani  if (strlen(y) == 3)
3939e49d9fbdc861c25c2480233147dee07f5fa9660Jordy Rose    strcat(x, y); // expected-warning{{String copy function overflows destination buffer}}
394067bbd0e11c71a33b51832532e836971be697699Lenny Maiorani}
395067bbd0e11c71a33b51832532e836971be697699Lenny Maiorani
396067bbd0e11c71a33b51832532e836971be697699Lenny Maioranivoid strcat_overflow_2(char *y) {
397067bbd0e11c71a33b51832532e836971be697699Lenny Maiorani  char x[4] = "12";
398067bbd0e11c71a33b51832532e836971be697699Lenny Maiorani  if (strlen(y) == 2)
3999e49d9fbdc861c25c2480233147dee07f5fa9660Jordy Rose    strcat(x, y); // expected-warning{{String copy function overflows destination buffer}}
400067bbd0e11c71a33b51832532e836971be697699Lenny Maiorani}
401067bbd0e11c71a33b51832532e836971be697699Lenny Maiorani
402067bbd0e11c71a33b51832532e836971be697699Lenny Maioranivoid strcat_no_overflow(char *y) {
403067bbd0e11c71a33b51832532e836971be697699Lenny Maiorani  char x[5] = "12";
404067bbd0e11c71a33b51832532e836971be697699Lenny Maiorani  if (strlen(y) == 2)
405067bbd0e11c71a33b51832532e836971be697699Lenny Maiorani    strcat(x, y); // no-warning
406067bbd0e11c71a33b51832532e836971be697699Lenny Maiorani}
407067bbd0e11c71a33b51832532e836971be697699Lenny Maiorani
408d5af0e17b00ab2ee6a8c1f352bb9eeb1cc5b2d07Jordy Rosevoid strcat_symbolic_dst_length(char *dst) {
409d5af0e17b00ab2ee6a8c1f352bb9eeb1cc5b2d07Jordy Rose	strcat(dst, "1234");
41043d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose  clang_analyzer_eval(strlen(dst) >= 4); // expected-warning{{TRUE}}
411d5af0e17b00ab2ee6a8c1f352bb9eeb1cc5b2d07Jordy Rose}
412d5af0e17b00ab2ee6a8c1f352bb9eeb1cc5b2d07Jordy Rose
413d5af0e17b00ab2ee6a8c1f352bb9eeb1cc5b2d07Jordy Rosevoid strcat_symbolic_src_length(char *src) {
414d5af0e17b00ab2ee6a8c1f352bb9eeb1cc5b2d07Jordy Rose	char dst[8] = "1234";
415d5af0e17b00ab2ee6a8c1f352bb9eeb1cc5b2d07Jordy Rose	strcat(dst, src);
41643d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose  clang_analyzer_eval(strlen(dst) >= 4); // expected-warning{{TRUE}}
417d5af0e17b00ab2ee6a8c1f352bb9eeb1cc5b2d07Jordy Rose}
418d5af0e17b00ab2ee6a8c1f352bb9eeb1cc5b2d07Jordy Rose
419e3d250e488241cbfe71a592df4d07d03ad89434aAnna Zaksvoid strcat_symbolic_dst_length_taint(char *dst) {
420e3d250e488241cbfe71a592df4d07d03ad89434aAnna Zaks  scanf("%s", dst); // Taint data.
421e3d250e488241cbfe71a592df4d07d03ad89434aAnna Zaks  strcat(dst, "1234");
42243d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose  clang_analyzer_eval(strlen(dst) >= 4); // expected-warning{{TRUE}}
423e3d250e488241cbfe71a592df4d07d03ad89434aAnna Zaks}
424e3d250e488241cbfe71a592df4d07d03ad89434aAnna Zaks
425d5af0e17b00ab2ee6a8c1f352bb9eeb1cc5b2d07Jordy Rosevoid strcat_unknown_src_length(char *src, int offset) {
426d5af0e17b00ab2ee6a8c1f352bb9eeb1cc5b2d07Jordy Rose	char dst[8] = "1234";
427d5af0e17b00ab2ee6a8c1f352bb9eeb1cc5b2d07Jordy Rose	strcat(dst, &src[offset]);
42843d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose  clang_analyzer_eval(strlen(dst) >= 4); // expected-warning{{TRUE}}
429d5af0e17b00ab2ee6a8c1f352bb9eeb1cc5b2d07Jordy Rose}
430d5af0e17b00ab2ee6a8c1f352bb9eeb1cc5b2d07Jordy Rose
431d5af0e17b00ab2ee6a8c1f352bb9eeb1cc5b2d07Jordy Rose// There is no strcat_unknown_dst_length because if we can't get a symbolic
432d5af0e17b00ab2ee6a8c1f352bb9eeb1cc5b2d07Jordy Rose// length for the "before" strlen, we won't be able to set one for "after".
433d5af0e17b00ab2ee6a8c1f352bb9eeb1cc5b2d07Jordy Rose
434d5af0e17b00ab2ee6a8c1f352bb9eeb1cc5b2d07Jordy Rosevoid strcat_too_big(char *dst, char *src) {
435d5af0e17b00ab2ee6a8c1f352bb9eeb1cc5b2d07Jordy Rose	if (strlen(dst) != (((size_t)0) - 2))
436d5af0e17b00ab2ee6a8c1f352bb9eeb1cc5b2d07Jordy Rose		return;
437d5af0e17b00ab2ee6a8c1f352bb9eeb1cc5b2d07Jordy Rose	if (strlen(src) != 2)
438d5af0e17b00ab2ee6a8c1f352bb9eeb1cc5b2d07Jordy Rose		return;
439d5af0e17b00ab2ee6a8c1f352bb9eeb1cc5b2d07Jordy Rose	strcat(dst, src); // expected-warning{{This expression will create a string whose length is too big to be represented as a size_t}}
440d5af0e17b00ab2ee6a8c1f352bb9eeb1cc5b2d07Jordy Rose}
441d5af0e17b00ab2ee6a8c1f352bb9eeb1cc5b2d07Jordy Rose
442067bbd0e11c71a33b51832532e836971be697699Lenny Maiorani
443067bbd0e11c71a33b51832532e836971be697699Lenny Maiorani//===----------------------------------------------------------------------===
4445e5f15062bcf4b62fda9062b453178f8b9bd0c2dJordy Rose// strncpy()
4455e5f15062bcf4b62fda9062b453178f8b9bd0c2dJordy Rose//===----------------------------------------------------------------------===
4465e5f15062bcf4b62fda9062b453178f8b9bd0c2dJordy Rose
4475e5f15062bcf4b62fda9062b453178f8b9bd0c2dJordy Rose#ifdef VARIANT
4485e5f15062bcf4b62fda9062b453178f8b9bd0c2dJordy Rose
4495e5f15062bcf4b62fda9062b453178f8b9bd0c2dJordy Rose#define __strncpy_chk BUILTIN(__strncpy_chk)
4505e5f15062bcf4b62fda9062b453178f8b9bd0c2dJordy Rosechar *__strncpy_chk(char *restrict s1, const char *restrict s2, size_t n, size_t destlen);
4515e5f15062bcf4b62fda9062b453178f8b9bd0c2dJordy Rose
4525e5f15062bcf4b62fda9062b453178f8b9bd0c2dJordy Rose#define strncpy(a,b,n) __strncpy_chk(a,b,n,(size_t)-1)
4535e5f15062bcf4b62fda9062b453178f8b9bd0c2dJordy Rose
4545e5f15062bcf4b62fda9062b453178f8b9bd0c2dJordy Rose#else /* VARIANT */
4555e5f15062bcf4b62fda9062b453178f8b9bd0c2dJordy Rose
4565e5f15062bcf4b62fda9062b453178f8b9bd0c2dJordy Rose#define strncpy BUILTIN(strncpy)
4575e5f15062bcf4b62fda9062b453178f8b9bd0c2dJordy Rosechar *strncpy(char *restrict s1, const char *restrict s2, size_t n);
4585e5f15062bcf4b62fda9062b453178f8b9bd0c2dJordy Rose
4595e5f15062bcf4b62fda9062b453178f8b9bd0c2dJordy Rose#endif /* VARIANT */
4605e5f15062bcf4b62fda9062b453178f8b9bd0c2dJordy Rose
4615e5f15062bcf4b62fda9062b453178f8b9bd0c2dJordy Rose
4625e5f15062bcf4b62fda9062b453178f8b9bd0c2dJordy Rosevoid strncpy_null_dst(char *x) {
4635e5f15062bcf4b62fda9062b453178f8b9bd0c2dJordy Rose  strncpy(NULL, x, 5); // expected-warning{{Null pointer argument in call to string copy function}}
4645e5f15062bcf4b62fda9062b453178f8b9bd0c2dJordy Rose}
4655e5f15062bcf4b62fda9062b453178f8b9bd0c2dJordy Rose
4665e5f15062bcf4b62fda9062b453178f8b9bd0c2dJordy Rosevoid strncpy_null_src(char *x) {
4675e5f15062bcf4b62fda9062b453178f8b9bd0c2dJordy Rose  strncpy(x, NULL, 5); // expected-warning{{Null pointer argument in call to string copy function}}
4685e5f15062bcf4b62fda9062b453178f8b9bd0c2dJordy Rose}
4695e5f15062bcf4b62fda9062b453178f8b9bd0c2dJordy Rose
4705e5f15062bcf4b62fda9062b453178f8b9bd0c2dJordy Rosevoid strncpy_fn(char *x) {
4715e5f15062bcf4b62fda9062b453178f8b9bd0c2dJordy Rose  strncpy(x, (char*)&strcpy_fn, 5); // expected-warning{{Argument to string copy function is the address of the function 'strcpy_fn', which is not a null-terminated string}}
4725e5f15062bcf4b62fda9062b453178f8b9bd0c2dJordy Rose}
4735e5f15062bcf4b62fda9062b453178f8b9bd0c2dJordy Rose
4745e5f15062bcf4b62fda9062b453178f8b9bd0c2dJordy Rosevoid strncpy_effects(char *x, char *y) {
4755e5f15062bcf4b62fda9062b453178f8b9bd0c2dJordy Rose  char a = x[0];
4765e5f15062bcf4b62fda9062b453178f8b9bd0c2dJordy Rose
47743d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose  clang_analyzer_eval(strncpy(x, y, 5) == x); // expected-warning{{TRUE}}
47843d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose  clang_analyzer_eval(strlen(x) == strlen(y)); // expected-warning{{UNKNOWN}}
47943d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose  clang_analyzer_eval(a == x[0]); // expected-warning{{UNKNOWN}}
4805e5f15062bcf4b62fda9062b453178f8b9bd0c2dJordy Rose}
4815e5f15062bcf4b62fda9062b453178f8b9bd0c2dJordy Rose
4825e5f15062bcf4b62fda9062b453178f8b9bd0c2dJordy Rosevoid strncpy_overflow(char *y) {
4835e5f15062bcf4b62fda9062b453178f8b9bd0c2dJordy Rose  char x[4];
4845e5f15062bcf4b62fda9062b453178f8b9bd0c2dJordy Rose  if (strlen(y) == 4)
4855e5f15062bcf4b62fda9062b453178f8b9bd0c2dJordy Rose    strncpy(x, y, 5); // expected-warning{{Size argument is greater than the length of the destination buffer}}
4865e5f15062bcf4b62fda9062b453178f8b9bd0c2dJordy Rose}
4875e5f15062bcf4b62fda9062b453178f8b9bd0c2dJordy Rose
4885e5f15062bcf4b62fda9062b453178f8b9bd0c2dJordy Rosevoid strncpy_no_overflow(char *y) {
4895e5f15062bcf4b62fda9062b453178f8b9bd0c2dJordy Rose  char x[4];
4905e5f15062bcf4b62fda9062b453178f8b9bd0c2dJordy Rose  if (strlen(y) == 3)
4915e5f15062bcf4b62fda9062b453178f8b9bd0c2dJordy Rose    strncpy(x, y, 5); // expected-warning{{Size argument is greater than the length of the destination buffer}}
4925e5f15062bcf4b62fda9062b453178f8b9bd0c2dJordy Rose}
4935e5f15062bcf4b62fda9062b453178f8b9bd0c2dJordy Rose
4945e5f15062bcf4b62fda9062b453178f8b9bd0c2dJordy Rosevoid strncpy_no_overflow2(char *y, int n) {
4955e5f15062bcf4b62fda9062b453178f8b9bd0c2dJordy Rose	if (n <= 4)
4965e5f15062bcf4b62fda9062b453178f8b9bd0c2dJordy Rose		return;
4975e5f15062bcf4b62fda9062b453178f8b9bd0c2dJordy Rose
4985e5f15062bcf4b62fda9062b453178f8b9bd0c2dJordy Rose  char x[4];
4995e5f15062bcf4b62fda9062b453178f8b9bd0c2dJordy Rose  if (strlen(y) == 3)
5005e5f15062bcf4b62fda9062b453178f8b9bd0c2dJordy Rose    strncpy(x, y, n); // expected-warning{{Size argument is greater than the length of the destination buffer}}
5015e5f15062bcf4b62fda9062b453178f8b9bd0c2dJordy Rose}
5025e5f15062bcf4b62fda9062b453178f8b9bd0c2dJordy Rose
5035e5f15062bcf4b62fda9062b453178f8b9bd0c2dJordy Rosevoid strncpy_truncate(char *y) {
5045e5f15062bcf4b62fda9062b453178f8b9bd0c2dJordy Rose  char x[4];
5055e5f15062bcf4b62fda9062b453178f8b9bd0c2dJordy Rose  if (strlen(y) == 4)
5065e5f15062bcf4b62fda9062b453178f8b9bd0c2dJordy Rose    strncpy(x, y, 3); // no-warning
5075e5f15062bcf4b62fda9062b453178f8b9bd0c2dJordy Rose}
5085e5f15062bcf4b62fda9062b453178f8b9bd0c2dJordy Rose
5095e5f15062bcf4b62fda9062b453178f8b9bd0c2dJordy Rosevoid strncpy_no_truncate(char *y) {
5105e5f15062bcf4b62fda9062b453178f8b9bd0c2dJordy Rose  char x[4];
5115e5f15062bcf4b62fda9062b453178f8b9bd0c2dJordy Rose  if (strlen(y) == 3)
5125e5f15062bcf4b62fda9062b453178f8b9bd0c2dJordy Rose    strncpy(x, y, 3); // no-warning
5135e5f15062bcf4b62fda9062b453178f8b9bd0c2dJordy Rose}
5145e5f15062bcf4b62fda9062b453178f8b9bd0c2dJordy Rose
5155e5f15062bcf4b62fda9062b453178f8b9bd0c2dJordy Rosevoid strncpy_exactly_matching_buffer(char *y) {
5165e5f15062bcf4b62fda9062b453178f8b9bd0c2dJordy Rose	char x[4];
5175e5f15062bcf4b62fda9062b453178f8b9bd0c2dJordy Rose	strncpy(x, y, 4); // no-warning
5185e5f15062bcf4b62fda9062b453178f8b9bd0c2dJordy Rose
5195e5f15062bcf4b62fda9062b453178f8b9bd0c2dJordy Rose	// strncpy does not null-terminate, so we have no idea what the strlen is
5205e5f15062bcf4b62fda9062b453178f8b9bd0c2dJordy Rose	// after this.
52143d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose  clang_analyzer_eval(strlen(x) > 4); // expected-warning{{UNKNOWN}}
5225e5f15062bcf4b62fda9062b453178f8b9bd0c2dJordy Rose}
5235e5f15062bcf4b62fda9062b453178f8b9bd0c2dJordy Rose
5245e5f15062bcf4b62fda9062b453178f8b9bd0c2dJordy Rosevoid strncpy_exactly_matching_buffer2(char *y) {
5255e5f15062bcf4b62fda9062b453178f8b9bd0c2dJordy Rose	if (strlen(y) >= 4)
5265e5f15062bcf4b62fda9062b453178f8b9bd0c2dJordy Rose		return;
5275e5f15062bcf4b62fda9062b453178f8b9bd0c2dJordy Rose
5285e5f15062bcf4b62fda9062b453178f8b9bd0c2dJordy Rose	char x[4];
5295e5f15062bcf4b62fda9062b453178f8b9bd0c2dJordy Rose	strncpy(x, y, 4); // no-warning
5305e5f15062bcf4b62fda9062b453178f8b9bd0c2dJordy Rose
5315e5f15062bcf4b62fda9062b453178f8b9bd0c2dJordy Rose	// This time, we know that y fits in x anyway.
53243d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose  clang_analyzer_eval(strlen(x) <= 3); // expected-warning{{TRUE}}
5335e5f15062bcf4b62fda9062b453178f8b9bd0c2dJordy Rose}
5345e5f15062bcf4b62fda9062b453178f8b9bd0c2dJordy Rose
5356e4244ee86a2d71af4eac791808f2dc50c7484e6Jordy Rosevoid strncpy_zero(char *src) {
5366e4244ee86a2d71af4eac791808f2dc50c7484e6Jordy Rose  char dst[] = "123";
5376e4244ee86a2d71af4eac791808f2dc50c7484e6Jordy Rose  strncpy(dst, src, 0); // no-warning
5386e4244ee86a2d71af4eac791808f2dc50c7484e6Jordy Rose}
5396e4244ee86a2d71af4eac791808f2dc50c7484e6Jordy Rose
5406e4244ee86a2d71af4eac791808f2dc50c7484e6Jordy Rosevoid strncpy_empty() {
5416e4244ee86a2d71af4eac791808f2dc50c7484e6Jordy Rose  char dst[] = "123";
5426e4244ee86a2d71af4eac791808f2dc50c7484e6Jordy Rose  char src[] = "";
5436e4244ee86a2d71af4eac791808f2dc50c7484e6Jordy Rose  strncpy(dst, src, 4); // no-warning
5446e4244ee86a2d71af4eac791808f2dc50c7484e6Jordy Rose}
5456e4244ee86a2d71af4eac791808f2dc50c7484e6Jordy Rose
5465e5f15062bcf4b62fda9062b453178f8b9bd0c2dJordy Rose//===----------------------------------------------------------------------===
547067bbd0e11c71a33b51832532e836971be697699Lenny Maiorani// strncat()
548067bbd0e11c71a33b51832532e836971be697699Lenny Maiorani//===----------------------------------------------------------------------===
549067bbd0e11c71a33b51832532e836971be697699Lenny Maiorani
550067bbd0e11c71a33b51832532e836971be697699Lenny Maiorani#ifdef VARIANT
551067bbd0e11c71a33b51832532e836971be697699Lenny Maiorani
552067bbd0e11c71a33b51832532e836971be697699Lenny Maiorani#define __strncat_chk BUILTIN(__strncat_chk)
553067bbd0e11c71a33b51832532e836971be697699Lenny Maioranichar *__strncat_chk(char *restrict s1, const char *restrict s2, size_t n, size_t destlen);
554067bbd0e11c71a33b51832532e836971be697699Lenny Maiorani
555067bbd0e11c71a33b51832532e836971be697699Lenny Maiorani#define strncat(a,b,c) __strncat_chk(a,b,c, (size_t)-1)
556067bbd0e11c71a33b51832532e836971be697699Lenny Maiorani
557067bbd0e11c71a33b51832532e836971be697699Lenny Maiorani#else /* VARIANT */
558067bbd0e11c71a33b51832532e836971be697699Lenny Maiorani
559067bbd0e11c71a33b51832532e836971be697699Lenny Maiorani#define strncat BUILTIN(strncat)
560067bbd0e11c71a33b51832532e836971be697699Lenny Maioranichar *strncat(char *restrict s1, const char *restrict s2, size_t n);
561067bbd0e11c71a33b51832532e836971be697699Lenny Maiorani
562067bbd0e11c71a33b51832532e836971be697699Lenny Maiorani#endif /* VARIANT */
563067bbd0e11c71a33b51832532e836971be697699Lenny Maiorani
564067bbd0e11c71a33b51832532e836971be697699Lenny Maiorani
565067bbd0e11c71a33b51832532e836971be697699Lenny Maioranivoid strncat_null_dst(char *x) {
5669e49d9fbdc861c25c2480233147dee07f5fa9660Jordy Rose  strncat(NULL, x, 4); // expected-warning{{Null pointer argument in call to string copy function}}
567067bbd0e11c71a33b51832532e836971be697699Lenny Maiorani}
568067bbd0e11c71a33b51832532e836971be697699Lenny Maiorani
569067bbd0e11c71a33b51832532e836971be697699Lenny Maioranivoid strncat_null_src(char *x) {
5709e49d9fbdc861c25c2480233147dee07f5fa9660Jordy Rose  strncat(x, NULL, 4); // expected-warning{{Null pointer argument in call to string copy function}}
571067bbd0e11c71a33b51832532e836971be697699Lenny Maiorani}
572067bbd0e11c71a33b51832532e836971be697699Lenny Maiorani
573067bbd0e11c71a33b51832532e836971be697699Lenny Maioranivoid strncat_fn(char *x) {
5749e49d9fbdc861c25c2480233147dee07f5fa9660Jordy Rose  strncat(x, (char*)&strncat_fn, 4); // expected-warning{{Argument to string copy function is the address of the function 'strncat_fn', which is not a null-terminated string}}
575067bbd0e11c71a33b51832532e836971be697699Lenny Maiorani}
576067bbd0e11c71a33b51832532e836971be697699Lenny Maiorani
577067bbd0e11c71a33b51832532e836971be697699Lenny Maioranivoid strncat_effects(char *y) {
578067bbd0e11c71a33b51832532e836971be697699Lenny Maiorani  char x[8] = "123";
579067bbd0e11c71a33b51832532e836971be697699Lenny Maiorani  size_t orig_len = strlen(x);
580067bbd0e11c71a33b51832532e836971be697699Lenny Maiorani  char a = x[0];
581067bbd0e11c71a33b51832532e836971be697699Lenny Maiorani
582067bbd0e11c71a33b51832532e836971be697699Lenny Maiorani  if (strlen(y) != 4)
583067bbd0e11c71a33b51832532e836971be697699Lenny Maiorani    return;
584067bbd0e11c71a33b51832532e836971be697699Lenny Maiorani
58543d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose  clang_analyzer_eval(strncat(x, y, strlen(y)) == x); // expected-warning{{TRUE}}
58643d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose  clang_analyzer_eval(strlen(x) == (orig_len + strlen(y))); // expected-warning{{TRUE}}
587067bbd0e11c71a33b51832532e836971be697699Lenny Maiorani}
588067bbd0e11c71a33b51832532e836971be697699Lenny Maiorani
589067bbd0e11c71a33b51832532e836971be697699Lenny Maioranivoid strncat_overflow_0(char *y) {
590067bbd0e11c71a33b51832532e836971be697699Lenny Maiorani  char x[4] = "12";
591067bbd0e11c71a33b51832532e836971be697699Lenny Maiorani  if (strlen(y) == 4)
5928912aaedb413b15f6dd1d8997d80e1d505f7d52fJordy Rose    strncat(x, y, strlen(y)); // expected-warning{{Size argument is greater than the free space in the destination buffer}}
593067bbd0e11c71a33b51832532e836971be697699Lenny Maiorani}
594067bbd0e11c71a33b51832532e836971be697699Lenny Maiorani
595067bbd0e11c71a33b51832532e836971be697699Lenny Maioranivoid strncat_overflow_1(char *y) {
596067bbd0e11c71a33b51832532e836971be697699Lenny Maiorani  char x[4] = "12";
597067bbd0e11c71a33b51832532e836971be697699Lenny Maiorani  if (strlen(y) == 3)
5988912aaedb413b15f6dd1d8997d80e1d505f7d52fJordy Rose    strncat(x, y, strlen(y)); // expected-warning{{Size argument is greater than the free space in the destination buffer}}
599067bbd0e11c71a33b51832532e836971be697699Lenny Maiorani}
600067bbd0e11c71a33b51832532e836971be697699Lenny Maiorani
601067bbd0e11c71a33b51832532e836971be697699Lenny Maioranivoid strncat_overflow_2(char *y) {
602067bbd0e11c71a33b51832532e836971be697699Lenny Maiorani  char x[4] = "12";
603067bbd0e11c71a33b51832532e836971be697699Lenny Maiorani  if (strlen(y) == 2)
6048912aaedb413b15f6dd1d8997d80e1d505f7d52fJordy Rose    strncat(x, y, strlen(y)); // expected-warning{{Size argument is greater than the free space in the destination buffer}}
605067bbd0e11c71a33b51832532e836971be697699Lenny Maiorani}
606067bbd0e11c71a33b51832532e836971be697699Lenny Maiorani
607067bbd0e11c71a33b51832532e836971be697699Lenny Maioranivoid strncat_overflow_3(char *y) {
608067bbd0e11c71a33b51832532e836971be697699Lenny Maiorani  char x[4] = "12";
609067bbd0e11c71a33b51832532e836971be697699Lenny Maiorani  if (strlen(y) == 4)
6108912aaedb413b15f6dd1d8997d80e1d505f7d52fJordy Rose    strncat(x, y, 2); // expected-warning{{Size argument is greater than the free space in the destination buffer}}
611067bbd0e11c71a33b51832532e836971be697699Lenny Maiorani}
612067bbd0e11c71a33b51832532e836971be697699Lenny Maioranivoid strncat_no_overflow_1(char *y) {
613067bbd0e11c71a33b51832532e836971be697699Lenny Maiorani  char x[5] = "12";
614067bbd0e11c71a33b51832532e836971be697699Lenny Maiorani  if (strlen(y) == 2)
615067bbd0e11c71a33b51832532e836971be697699Lenny Maiorani    strncat(x, y, strlen(y)); // no-warning
616067bbd0e11c71a33b51832532e836971be697699Lenny Maiorani}
617067bbd0e11c71a33b51832532e836971be697699Lenny Maiorani
618067bbd0e11c71a33b51832532e836971be697699Lenny Maioranivoid strncat_no_overflow_2(char *y) {
619067bbd0e11c71a33b51832532e836971be697699Lenny Maiorani  char x[4] = "12";
620067bbd0e11c71a33b51832532e836971be697699Lenny Maiorani  if (strlen(y) == 4)
621067bbd0e11c71a33b51832532e836971be697699Lenny Maiorani    strncat(x, y, 1); // no-warning
622067bbd0e11c71a33b51832532e836971be697699Lenny Maiorani}
623318dd92ad834857ea5bb91de288c1eb56cdbec1aLenny Maiorani
6248912aaedb413b15f6dd1d8997d80e1d505f7d52fJordy Rosevoid strncat_symbolic_dst_length(char *dst) {
6258912aaedb413b15f6dd1d8997d80e1d505f7d52fJordy Rose  strncat(dst, "1234", 5);
62643d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose  clang_analyzer_eval(strlen(dst) >= 4); // expected-warning{{TRUE}}
6278912aaedb413b15f6dd1d8997d80e1d505f7d52fJordy Rose}
6288912aaedb413b15f6dd1d8997d80e1d505f7d52fJordy Rose
6298912aaedb413b15f6dd1d8997d80e1d505f7d52fJordy Rosevoid strncat_symbolic_src_length(char *src) {
6308912aaedb413b15f6dd1d8997d80e1d505f7d52fJordy Rose  char dst[8] = "1234";
6318912aaedb413b15f6dd1d8997d80e1d505f7d52fJordy Rose  strncat(dst, src, 3);
63243d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose  clang_analyzer_eval(strlen(dst) >= 4); // expected-warning{{TRUE}}
6338912aaedb413b15f6dd1d8997d80e1d505f7d52fJordy Rose
6348912aaedb413b15f6dd1d8997d80e1d505f7d52fJordy Rose  char dst2[8] = "1234";
6358912aaedb413b15f6dd1d8997d80e1d505f7d52fJordy Rose  strncat(dst2, src, 4); // expected-warning{{Size argument is greater than the free space in the destination buffer}}
6368912aaedb413b15f6dd1d8997d80e1d505f7d52fJordy Rose}
6378912aaedb413b15f6dd1d8997d80e1d505f7d52fJordy Rose
6388912aaedb413b15f6dd1d8997d80e1d505f7d52fJordy Rosevoid strncat_unknown_src_length(char *src, int offset) {
6398912aaedb413b15f6dd1d8997d80e1d505f7d52fJordy Rose  char dst[8] = "1234";
6408912aaedb413b15f6dd1d8997d80e1d505f7d52fJordy Rose  strncat(dst, &src[offset], 3);
64143d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose  clang_analyzer_eval(strlen(dst) >= 4); // expected-warning{{TRUE}}
6428912aaedb413b15f6dd1d8997d80e1d505f7d52fJordy Rose
6438912aaedb413b15f6dd1d8997d80e1d505f7d52fJordy Rose  char dst2[8] = "1234";
6448912aaedb413b15f6dd1d8997d80e1d505f7d52fJordy Rose  strncat(dst2, &src[offset], 4); // expected-warning{{Size argument is greater than the free space in the destination buffer}}
6458912aaedb413b15f6dd1d8997d80e1d505f7d52fJordy Rose}
6468912aaedb413b15f6dd1d8997d80e1d505f7d52fJordy Rose
6478912aaedb413b15f6dd1d8997d80e1d505f7d52fJordy Rose// There is no strncat_unknown_dst_length because if we can't get a symbolic
6488912aaedb413b15f6dd1d8997d80e1d505f7d52fJordy Rose// length for the "before" strlen, we won't be able to set one for "after".
6498912aaedb413b15f6dd1d8997d80e1d505f7d52fJordy Rose
6508912aaedb413b15f6dd1d8997d80e1d505f7d52fJordy Rosevoid strncat_symbolic_limit(unsigned limit) {
6518912aaedb413b15f6dd1d8997d80e1d505f7d52fJordy Rose  char dst[6] = "1234";
6528912aaedb413b15f6dd1d8997d80e1d505f7d52fJordy Rose  char src[] = "567";
6538912aaedb413b15f6dd1d8997d80e1d505f7d52fJordy Rose  strncat(dst, src, limit); // no-warning
65443d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose
65543d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose  clang_analyzer_eval(strlen(dst) >= 4); // expected-warning{{TRUE}}
65643d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose  clang_analyzer_eval(strlen(dst) == 4); // expected-warning{{UNKNOWN}}
6578912aaedb413b15f6dd1d8997d80e1d505f7d52fJordy Rose}
6588912aaedb413b15f6dd1d8997d80e1d505f7d52fJordy Rose
6598912aaedb413b15f6dd1d8997d80e1d505f7d52fJordy Rosevoid strncat_unknown_limit(float limit) {
6608912aaedb413b15f6dd1d8997d80e1d505f7d52fJordy Rose  char dst[6] = "1234";
6618912aaedb413b15f6dd1d8997d80e1d505f7d52fJordy Rose  char src[] = "567";
6628912aaedb413b15f6dd1d8997d80e1d505f7d52fJordy Rose  strncat(dst, src, (size_t)limit); // no-warning
66343d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose
66443d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose  clang_analyzer_eval(strlen(dst) >= 4); // expected-warning{{TRUE}}
66543d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose  clang_analyzer_eval(strlen(dst) == 4); // expected-warning{{UNKNOWN}}
6668912aaedb413b15f6dd1d8997d80e1d505f7d52fJordy Rose}
6678912aaedb413b15f6dd1d8997d80e1d505f7d52fJordy Rose
6688912aaedb413b15f6dd1d8997d80e1d505f7d52fJordy Rosevoid strncat_too_big(char *dst, char *src) {
6698912aaedb413b15f6dd1d8997d80e1d505f7d52fJordy Rose  if (strlen(dst) != (((size_t)0) - 2))
6708912aaedb413b15f6dd1d8997d80e1d505f7d52fJordy Rose    return;
6718912aaedb413b15f6dd1d8997d80e1d505f7d52fJordy Rose  if (strlen(src) != 2)
6728912aaedb413b15f6dd1d8997d80e1d505f7d52fJordy Rose    return;
6738912aaedb413b15f6dd1d8997d80e1d505f7d52fJordy Rose  strncat(dst, src, 2); // expected-warning{{This expression will create a string whose length is too big to be represented as a size_t}}
6748912aaedb413b15f6dd1d8997d80e1d505f7d52fJordy Rose}
6758912aaedb413b15f6dd1d8997d80e1d505f7d52fJordy Rose
6766e4244ee86a2d71af4eac791808f2dc50c7484e6Jordy Rosevoid strncat_zero(char *src) {
6776e4244ee86a2d71af4eac791808f2dc50c7484e6Jordy Rose  char dst[] = "123";
6786e4244ee86a2d71af4eac791808f2dc50c7484e6Jordy Rose  strncat(dst, src, 0); // no-warning
6796e4244ee86a2d71af4eac791808f2dc50c7484e6Jordy Rose}
6806e4244ee86a2d71af4eac791808f2dc50c7484e6Jordy Rose
6816e4244ee86a2d71af4eac791808f2dc50c7484e6Jordy Rosevoid strncat_empty() {
6826e4244ee86a2d71af4eac791808f2dc50c7484e6Jordy Rose  char dst[8] = "123";
6836e4244ee86a2d71af4eac791808f2dc50c7484e6Jordy Rose  char src[] = "";
6846e4244ee86a2d71af4eac791808f2dc50c7484e6Jordy Rose  strncat(dst, src, 4); // no-warning
6856e4244ee86a2d71af4eac791808f2dc50c7484e6Jordy Rose}
6866e4244ee86a2d71af4eac791808f2dc50c7484e6Jordy Rose
687318dd92ad834857ea5bb91de288c1eb56cdbec1aLenny Maiorani//===----------------------------------------------------------------------===
688318dd92ad834857ea5bb91de288c1eb56cdbec1aLenny Maiorani// strcmp()
689318dd92ad834857ea5bb91de288c1eb56cdbec1aLenny Maiorani//===----------------------------------------------------------------------===
690318dd92ad834857ea5bb91de288c1eb56cdbec1aLenny Maiorani
691318dd92ad834857ea5bb91de288c1eb56cdbec1aLenny Maiorani#define strcmp BUILTIN(strcmp)
692adc42d412d747391dbcee234610f00b0f087cf7bJordy Roseint strcmp(const char * s1, const char * s2);
693318dd92ad834857ea5bb91de288c1eb56cdbec1aLenny Maiorani
694318dd92ad834857ea5bb91de288c1eb56cdbec1aLenny Maioranivoid strcmp_constant0() {
69543d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose  clang_analyzer_eval(strcmp("123", "123") == 0); // expected-warning{{TRUE}}
696318dd92ad834857ea5bb91de288c1eb56cdbec1aLenny Maiorani}
697318dd92ad834857ea5bb91de288c1eb56cdbec1aLenny Maiorani
698318dd92ad834857ea5bb91de288c1eb56cdbec1aLenny Maioranivoid strcmp_constant_and_var_0() {
699318dd92ad834857ea5bb91de288c1eb56cdbec1aLenny Maiorani  char *x = "123";
70043d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose  clang_analyzer_eval(strcmp(x, "123") == 0); // expected-warning{{TRUE}}
701318dd92ad834857ea5bb91de288c1eb56cdbec1aLenny Maiorani}
702318dd92ad834857ea5bb91de288c1eb56cdbec1aLenny Maiorani
703318dd92ad834857ea5bb91de288c1eb56cdbec1aLenny Maioranivoid strcmp_constant_and_var_1() {
704318dd92ad834857ea5bb91de288c1eb56cdbec1aLenny Maiorani  char *x = "123";
70543d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose  clang_analyzer_eval(strcmp("123", x) == 0); // expected-warning{{TRUE}}
706318dd92ad834857ea5bb91de288c1eb56cdbec1aLenny Maiorani}
707318dd92ad834857ea5bb91de288c1eb56cdbec1aLenny Maiorani
708318dd92ad834857ea5bb91de288c1eb56cdbec1aLenny Maioranivoid strcmp_0() {
709318dd92ad834857ea5bb91de288c1eb56cdbec1aLenny Maiorani  char *x = "123";
710318dd92ad834857ea5bb91de288c1eb56cdbec1aLenny Maiorani  char *y = "123";
71143d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose  clang_analyzer_eval(strcmp(x, y) == 0); // expected-warning{{TRUE}}
712318dd92ad834857ea5bb91de288c1eb56cdbec1aLenny Maiorani}
713318dd92ad834857ea5bb91de288c1eb56cdbec1aLenny Maiorani
714318dd92ad834857ea5bb91de288c1eb56cdbec1aLenny Maioranivoid strcmp_1() {
715318dd92ad834857ea5bb91de288c1eb56cdbec1aLenny Maiorani  char *x = "234";
716318dd92ad834857ea5bb91de288c1eb56cdbec1aLenny Maiorani  char *y = "123";
71743d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose  clang_analyzer_eval(strcmp(x, y) == 1); // expected-warning{{TRUE}}
718318dd92ad834857ea5bb91de288c1eb56cdbec1aLenny Maiorani}
719318dd92ad834857ea5bb91de288c1eb56cdbec1aLenny Maiorani
720318dd92ad834857ea5bb91de288c1eb56cdbec1aLenny Maioranivoid strcmp_2() {
721318dd92ad834857ea5bb91de288c1eb56cdbec1aLenny Maiorani  char *x = "123";
722318dd92ad834857ea5bb91de288c1eb56cdbec1aLenny Maiorani  char *y = "234";
72343d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose  clang_analyzer_eval(strcmp(x, y) == -1); // expected-warning{{TRUE}}
724318dd92ad834857ea5bb91de288c1eb56cdbec1aLenny Maiorani}
725318dd92ad834857ea5bb91de288c1eb56cdbec1aLenny Maiorani
726318dd92ad834857ea5bb91de288c1eb56cdbec1aLenny Maioranivoid strcmp_null_0() {
727318dd92ad834857ea5bb91de288c1eb56cdbec1aLenny Maiorani  char *x = NULL;
728318dd92ad834857ea5bb91de288c1eb56cdbec1aLenny Maiorani  char *y = "123";
7299e49d9fbdc861c25c2480233147dee07f5fa9660Jordy Rose  strcmp(x, y); // expected-warning{{Null pointer argument in call to string comparison function}}
730318dd92ad834857ea5bb91de288c1eb56cdbec1aLenny Maiorani}
731318dd92ad834857ea5bb91de288c1eb56cdbec1aLenny Maiorani
732318dd92ad834857ea5bb91de288c1eb56cdbec1aLenny Maioranivoid strcmp_null_1() {
733318dd92ad834857ea5bb91de288c1eb56cdbec1aLenny Maiorani  char *x = "123";
734318dd92ad834857ea5bb91de288c1eb56cdbec1aLenny Maiorani  char *y = NULL;
7359e49d9fbdc861c25c2480233147dee07f5fa9660Jordy Rose  strcmp(x, y); // expected-warning{{Null pointer argument in call to string comparison function}}
736318dd92ad834857ea5bb91de288c1eb56cdbec1aLenny Maiorani}
737318dd92ad834857ea5bb91de288c1eb56cdbec1aLenny Maiorani
738318dd92ad834857ea5bb91de288c1eb56cdbec1aLenny Maioranivoid strcmp_diff_length_0() {
739318dd92ad834857ea5bb91de288c1eb56cdbec1aLenny Maiorani  char *x = "12345";
740318dd92ad834857ea5bb91de288c1eb56cdbec1aLenny Maiorani  char *y = "234";
74143d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose  clang_analyzer_eval(strcmp(x, y) == -1); // expected-warning{{TRUE}}
742318dd92ad834857ea5bb91de288c1eb56cdbec1aLenny Maiorani}
743318dd92ad834857ea5bb91de288c1eb56cdbec1aLenny Maiorani
744318dd92ad834857ea5bb91de288c1eb56cdbec1aLenny Maioranivoid strcmp_diff_length_1() {
745318dd92ad834857ea5bb91de288c1eb56cdbec1aLenny Maiorani  char *x = "123";
746318dd92ad834857ea5bb91de288c1eb56cdbec1aLenny Maiorani  char *y = "23456";
74743d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose  clang_analyzer_eval(strcmp(x, y) == -1); // expected-warning{{TRUE}}
748318dd92ad834857ea5bb91de288c1eb56cdbec1aLenny Maiorani}
749318dd92ad834857ea5bb91de288c1eb56cdbec1aLenny Maiorani
750318dd92ad834857ea5bb91de288c1eb56cdbec1aLenny Maioranivoid strcmp_diff_length_2() {
751318dd92ad834857ea5bb91de288c1eb56cdbec1aLenny Maiorani  char *x = "12345";
752318dd92ad834857ea5bb91de288c1eb56cdbec1aLenny Maiorani  char *y = "123";
75343d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose  clang_analyzer_eval(strcmp(x, y) == 1); // expected-warning{{TRUE}}
754318dd92ad834857ea5bb91de288c1eb56cdbec1aLenny Maiorani}
755318dd92ad834857ea5bb91de288c1eb56cdbec1aLenny Maiorani
756318dd92ad834857ea5bb91de288c1eb56cdbec1aLenny Maioranivoid strcmp_diff_length_3() {
757318dd92ad834857ea5bb91de288c1eb56cdbec1aLenny Maiorani  char *x = "123";
758318dd92ad834857ea5bb91de288c1eb56cdbec1aLenny Maiorani  char *y = "12345";
75943d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose  clang_analyzer_eval(strcmp(x, y) == -1); // expected-warning{{TRUE}}
760318dd92ad834857ea5bb91de288c1eb56cdbec1aLenny Maiorani}
761318dd92ad834857ea5bb91de288c1eb56cdbec1aLenny Maiorani
762adc42d412d747391dbcee234610f00b0f087cf7bJordy Rosevoid strcmp_embedded_null () {
76343d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose	clang_analyzer_eval(strcmp("\0z", "\0y") == 0); // expected-warning{{TRUE}}
764adc42d412d747391dbcee234610f00b0f087cf7bJordy Rose}
765adc42d412d747391dbcee234610f00b0f087cf7bJordy Rose
766adc42d412d747391dbcee234610f00b0f087cf7bJordy Rosevoid strcmp_unknown_arg (char *unknown) {
76743d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose	clang_analyzer_eval(strcmp(unknown, unknown) == 0); // expected-warning{{TRUE}}
768adc42d412d747391dbcee234610f00b0f087cf7bJordy Rose}
769adc42d412d747391dbcee234610f00b0f087cf7bJordy Rose
770357f6ee9f1f6f8e5027377cb3e5907c62c4fe3dfLenny Maiorani//===----------------------------------------------------------------------===
771357f6ee9f1f6f8e5027377cb3e5907c62c4fe3dfLenny Maiorani// strncmp()
772357f6ee9f1f6f8e5027377cb3e5907c62c4fe3dfLenny Maiorani//===----------------------------------------------------------------------===
773357f6ee9f1f6f8e5027377cb3e5907c62c4fe3dfLenny Maiorani
774357f6ee9f1f6f8e5027377cb3e5907c62c4fe3dfLenny Maiorani#define strncmp BUILTIN(strncmp)
775adc42d412d747391dbcee234610f00b0f087cf7bJordy Roseint strncmp(const char *s1, const char *s2, size_t n);
776357f6ee9f1f6f8e5027377cb3e5907c62c4fe3dfLenny Maiorani
777357f6ee9f1f6f8e5027377cb3e5907c62c4fe3dfLenny Maioranivoid strncmp_constant0() {
77843d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose  clang_analyzer_eval(strncmp("123", "123", 3) == 0); // expected-warning{{TRUE}}
779357f6ee9f1f6f8e5027377cb3e5907c62c4fe3dfLenny Maiorani}
780357f6ee9f1f6f8e5027377cb3e5907c62c4fe3dfLenny Maiorani
781357f6ee9f1f6f8e5027377cb3e5907c62c4fe3dfLenny Maioranivoid strncmp_constant_and_var_0() {
782357f6ee9f1f6f8e5027377cb3e5907c62c4fe3dfLenny Maiorani  char *x = "123";
78343d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose  clang_analyzer_eval(strncmp(x, "123", 3) == 0); // expected-warning{{TRUE}}
784357f6ee9f1f6f8e5027377cb3e5907c62c4fe3dfLenny Maiorani}
785357f6ee9f1f6f8e5027377cb3e5907c62c4fe3dfLenny Maiorani
786357f6ee9f1f6f8e5027377cb3e5907c62c4fe3dfLenny Maioranivoid strncmp_constant_and_var_1() {
787357f6ee9f1f6f8e5027377cb3e5907c62c4fe3dfLenny Maiorani  char *x = "123";
78843d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose  clang_analyzer_eval(strncmp("123", x, 3) == 0); // expected-warning{{TRUE}}
789357f6ee9f1f6f8e5027377cb3e5907c62c4fe3dfLenny Maiorani}
790357f6ee9f1f6f8e5027377cb3e5907c62c4fe3dfLenny Maiorani
791357f6ee9f1f6f8e5027377cb3e5907c62c4fe3dfLenny Maioranivoid strncmp_0() {
792357f6ee9f1f6f8e5027377cb3e5907c62c4fe3dfLenny Maiorani  char *x = "123";
793357f6ee9f1f6f8e5027377cb3e5907c62c4fe3dfLenny Maiorani  char *y = "123";
79443d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose  clang_analyzer_eval(strncmp(x, y, 3) == 0); // expected-warning{{TRUE}}
795357f6ee9f1f6f8e5027377cb3e5907c62c4fe3dfLenny Maiorani}
796357f6ee9f1f6f8e5027377cb3e5907c62c4fe3dfLenny Maiorani
797357f6ee9f1f6f8e5027377cb3e5907c62c4fe3dfLenny Maioranivoid strncmp_1() {
798357f6ee9f1f6f8e5027377cb3e5907c62c4fe3dfLenny Maiorani  char *x = "234";
799357f6ee9f1f6f8e5027377cb3e5907c62c4fe3dfLenny Maiorani  char *y = "123";
80043d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose  clang_analyzer_eval(strncmp(x, y, 3) == 1); // expected-warning{{TRUE}}
801357f6ee9f1f6f8e5027377cb3e5907c62c4fe3dfLenny Maiorani}
802357f6ee9f1f6f8e5027377cb3e5907c62c4fe3dfLenny Maiorani
803357f6ee9f1f6f8e5027377cb3e5907c62c4fe3dfLenny Maioranivoid strncmp_2() {
804357f6ee9f1f6f8e5027377cb3e5907c62c4fe3dfLenny Maiorani  char *x = "123";
805357f6ee9f1f6f8e5027377cb3e5907c62c4fe3dfLenny Maiorani  char *y = "234";
80643d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose  clang_analyzer_eval(strncmp(x, y, 3) == -1); // expected-warning{{TRUE}}
807357f6ee9f1f6f8e5027377cb3e5907c62c4fe3dfLenny Maiorani}
808357f6ee9f1f6f8e5027377cb3e5907c62c4fe3dfLenny Maiorani
809357f6ee9f1f6f8e5027377cb3e5907c62c4fe3dfLenny Maioranivoid strncmp_null_0() {
810357f6ee9f1f6f8e5027377cb3e5907c62c4fe3dfLenny Maiorani  char *x = NULL;
811357f6ee9f1f6f8e5027377cb3e5907c62c4fe3dfLenny Maiorani  char *y = "123";
8129e49d9fbdc861c25c2480233147dee07f5fa9660Jordy Rose  strncmp(x, y, 3); // expected-warning{{Null pointer argument in call to string comparison function}}
813357f6ee9f1f6f8e5027377cb3e5907c62c4fe3dfLenny Maiorani}
814357f6ee9f1f6f8e5027377cb3e5907c62c4fe3dfLenny Maiorani
815357f6ee9f1f6f8e5027377cb3e5907c62c4fe3dfLenny Maioranivoid strncmp_null_1() {
816357f6ee9f1f6f8e5027377cb3e5907c62c4fe3dfLenny Maiorani  char *x = "123";
817357f6ee9f1f6f8e5027377cb3e5907c62c4fe3dfLenny Maiorani  char *y = NULL;
8189e49d9fbdc861c25c2480233147dee07f5fa9660Jordy Rose  strncmp(x, y, 3); // expected-warning{{Null pointer argument in call to string comparison function}}
819357f6ee9f1f6f8e5027377cb3e5907c62c4fe3dfLenny Maiorani}
820357f6ee9f1f6f8e5027377cb3e5907c62c4fe3dfLenny Maiorani
821357f6ee9f1f6f8e5027377cb3e5907c62c4fe3dfLenny Maioranivoid strncmp_diff_length_0() {
822357f6ee9f1f6f8e5027377cb3e5907c62c4fe3dfLenny Maiorani  char *x = "12345";
823357f6ee9f1f6f8e5027377cb3e5907c62c4fe3dfLenny Maiorani  char *y = "234";
82443d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose  clang_analyzer_eval(strncmp(x, y, 5) == -1); // expected-warning{{TRUE}}
825357f6ee9f1f6f8e5027377cb3e5907c62c4fe3dfLenny Maiorani}
826357f6ee9f1f6f8e5027377cb3e5907c62c4fe3dfLenny Maiorani
827357f6ee9f1f6f8e5027377cb3e5907c62c4fe3dfLenny Maioranivoid strncmp_diff_length_1() {
828357f6ee9f1f6f8e5027377cb3e5907c62c4fe3dfLenny Maiorani  char *x = "123";
829357f6ee9f1f6f8e5027377cb3e5907c62c4fe3dfLenny Maiorani  char *y = "23456";
83043d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose  clang_analyzer_eval(strncmp(x, y, 5) == -1); // expected-warning{{TRUE}}
831357f6ee9f1f6f8e5027377cb3e5907c62c4fe3dfLenny Maiorani}
832357f6ee9f1f6f8e5027377cb3e5907c62c4fe3dfLenny Maiorani
833357f6ee9f1f6f8e5027377cb3e5907c62c4fe3dfLenny Maioranivoid strncmp_diff_length_2() {
834357f6ee9f1f6f8e5027377cb3e5907c62c4fe3dfLenny Maiorani  char *x = "12345";
835357f6ee9f1f6f8e5027377cb3e5907c62c4fe3dfLenny Maiorani  char *y = "123";
83643d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose  clang_analyzer_eval(strncmp(x, y, 5) == 1); // expected-warning{{TRUE}}
837357f6ee9f1f6f8e5027377cb3e5907c62c4fe3dfLenny Maiorani}
838357f6ee9f1f6f8e5027377cb3e5907c62c4fe3dfLenny Maiorani
839357f6ee9f1f6f8e5027377cb3e5907c62c4fe3dfLenny Maioranivoid strncmp_diff_length_3() {
840357f6ee9f1f6f8e5027377cb3e5907c62c4fe3dfLenny Maiorani  char *x = "123";
841357f6ee9f1f6f8e5027377cb3e5907c62c4fe3dfLenny Maiorani  char *y = "12345";
84243d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose  clang_analyzer_eval(strncmp(x, y, 5) == -1); // expected-warning{{TRUE}}
843357f6ee9f1f6f8e5027377cb3e5907c62c4fe3dfLenny Maiorani}
844357f6ee9f1f6f8e5027377cb3e5907c62c4fe3dfLenny Maiorani
845357f6ee9f1f6f8e5027377cb3e5907c62c4fe3dfLenny Maioranivoid strncmp_diff_length_4() {
846357f6ee9f1f6f8e5027377cb3e5907c62c4fe3dfLenny Maiorani  char *x = "123";
847357f6ee9f1f6f8e5027377cb3e5907c62c4fe3dfLenny Maiorani  char *y = "12345";
84843d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose  clang_analyzer_eval(strncmp(x, y, 3) == 0); // expected-warning{{TRUE}}
849357f6ee9f1f6f8e5027377cb3e5907c62c4fe3dfLenny Maiorani}
850357f6ee9f1f6f8e5027377cb3e5907c62c4fe3dfLenny Maiorani
851357f6ee9f1f6f8e5027377cb3e5907c62c4fe3dfLenny Maioranivoid strncmp_diff_length_5() {
852357f6ee9f1f6f8e5027377cb3e5907c62c4fe3dfLenny Maiorani  char *x = "012";
853357f6ee9f1f6f8e5027377cb3e5907c62c4fe3dfLenny Maiorani  char *y = "12345";
85443d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose  clang_analyzer_eval(strncmp(x, y, 3) == -1); // expected-warning{{TRUE}}
855357f6ee9f1f6f8e5027377cb3e5907c62c4fe3dfLenny Maiorani}
856357f6ee9f1f6f8e5027377cb3e5907c62c4fe3dfLenny Maiorani
857357f6ee9f1f6f8e5027377cb3e5907c62c4fe3dfLenny Maioranivoid strncmp_diff_length_6() {
858357f6ee9f1f6f8e5027377cb3e5907c62c4fe3dfLenny Maiorani  char *x = "234";
859357f6ee9f1f6f8e5027377cb3e5907c62c4fe3dfLenny Maiorani  char *y = "12345";
86043d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose  clang_analyzer_eval(strncmp(x, y, 3) == 1); // expected-warning{{TRUE}}
861357f6ee9f1f6f8e5027377cb3e5907c62c4fe3dfLenny Maiorani}
862357f6ee9f1f6f8e5027377cb3e5907c62c4fe3dfLenny Maiorani
863adc42d412d747391dbcee234610f00b0f087cf7bJordy Rosevoid strncmp_embedded_null () {
86443d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose	clang_analyzer_eval(strncmp("ab\0zz", "ab\0yy", 4) == 0); // expected-warning{{TRUE}}
865adc42d412d747391dbcee234610f00b0f087cf7bJordy Rose}
866adc42d412d747391dbcee234610f00b0f087cf7bJordy Rose
867bd1d16a1792cd6ea5ede9869e18d781e3fc1a8c3Lenny Maiorani//===----------------------------------------------------------------------===
868bd1d16a1792cd6ea5ede9869e18d781e3fc1a8c3Lenny Maiorani// strcasecmp()
869bd1d16a1792cd6ea5ede9869e18d781e3fc1a8c3Lenny Maiorani//===----------------------------------------------------------------------===
870bd1d16a1792cd6ea5ede9869e18d781e3fc1a8c3Lenny Maiorani
871bd1d16a1792cd6ea5ede9869e18d781e3fc1a8c3Lenny Maiorani#define strcasecmp BUILTIN(strcasecmp)
872adc42d412d747391dbcee234610f00b0f087cf7bJordy Roseint strcasecmp(const char *s1, const char *s2);
873bd1d16a1792cd6ea5ede9869e18d781e3fc1a8c3Lenny Maiorani
874bd1d16a1792cd6ea5ede9869e18d781e3fc1a8c3Lenny Maioranivoid strcasecmp_constant0() {
87543d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose  clang_analyzer_eval(strcasecmp("abc", "Abc") == 0); // expected-warning{{TRUE}}
876bd1d16a1792cd6ea5ede9869e18d781e3fc1a8c3Lenny Maiorani}
877bd1d16a1792cd6ea5ede9869e18d781e3fc1a8c3Lenny Maiorani
878bd1d16a1792cd6ea5ede9869e18d781e3fc1a8c3Lenny Maioranivoid strcasecmp_constant_and_var_0() {
879bd1d16a1792cd6ea5ede9869e18d781e3fc1a8c3Lenny Maiorani  char *x = "abc";
88043d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose  clang_analyzer_eval(strcasecmp(x, "Abc") == 0); // expected-warning{{TRUE}}
881bd1d16a1792cd6ea5ede9869e18d781e3fc1a8c3Lenny Maiorani}
882bd1d16a1792cd6ea5ede9869e18d781e3fc1a8c3Lenny Maiorani
883bd1d16a1792cd6ea5ede9869e18d781e3fc1a8c3Lenny Maioranivoid strcasecmp_constant_and_var_1() {
884bd1d16a1792cd6ea5ede9869e18d781e3fc1a8c3Lenny Maiorani  char *x = "abc";
88543d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose  clang_analyzer_eval(strcasecmp("Abc", x) == 0); // expected-warning{{TRUE}}
886bd1d16a1792cd6ea5ede9869e18d781e3fc1a8c3Lenny Maiorani}
887bd1d16a1792cd6ea5ede9869e18d781e3fc1a8c3Lenny Maiorani
888bd1d16a1792cd6ea5ede9869e18d781e3fc1a8c3Lenny Maioranivoid strcasecmp_0() {
889bd1d16a1792cd6ea5ede9869e18d781e3fc1a8c3Lenny Maiorani  char *x = "abc";
890bd1d16a1792cd6ea5ede9869e18d781e3fc1a8c3Lenny Maiorani  char *y = "Abc";
89143d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose  clang_analyzer_eval(strcasecmp(x, y) == 0); // expected-warning{{TRUE}}
892bd1d16a1792cd6ea5ede9869e18d781e3fc1a8c3Lenny Maiorani}
893bd1d16a1792cd6ea5ede9869e18d781e3fc1a8c3Lenny Maiorani
894bd1d16a1792cd6ea5ede9869e18d781e3fc1a8c3Lenny Maioranivoid strcasecmp_1() {
895bd1d16a1792cd6ea5ede9869e18d781e3fc1a8c3Lenny Maiorani  char *x = "Bcd";
896bd1d16a1792cd6ea5ede9869e18d781e3fc1a8c3Lenny Maiorani  char *y = "abc";
89743d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose  clang_analyzer_eval(strcasecmp(x, y) == 1); // expected-warning{{TRUE}}
898bd1d16a1792cd6ea5ede9869e18d781e3fc1a8c3Lenny Maiorani}
899bd1d16a1792cd6ea5ede9869e18d781e3fc1a8c3Lenny Maiorani
900bd1d16a1792cd6ea5ede9869e18d781e3fc1a8c3Lenny Maioranivoid strcasecmp_2() {
901bd1d16a1792cd6ea5ede9869e18d781e3fc1a8c3Lenny Maiorani  char *x = "abc";
902bd1d16a1792cd6ea5ede9869e18d781e3fc1a8c3Lenny Maiorani  char *y = "Bcd";
90343d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose  clang_analyzer_eval(strcasecmp(x, y) == -1); // expected-warning{{TRUE}}
904bd1d16a1792cd6ea5ede9869e18d781e3fc1a8c3Lenny Maiorani}
905bd1d16a1792cd6ea5ede9869e18d781e3fc1a8c3Lenny Maiorani
906bd1d16a1792cd6ea5ede9869e18d781e3fc1a8c3Lenny Maioranivoid strcasecmp_null_0() {
907bd1d16a1792cd6ea5ede9869e18d781e3fc1a8c3Lenny Maiorani  char *x = NULL;
908bd1d16a1792cd6ea5ede9869e18d781e3fc1a8c3Lenny Maiorani  char *y = "123";
9099e49d9fbdc861c25c2480233147dee07f5fa9660Jordy Rose  strcasecmp(x, y); // expected-warning{{Null pointer argument in call to string comparison function}}
910bd1d16a1792cd6ea5ede9869e18d781e3fc1a8c3Lenny Maiorani}
911bd1d16a1792cd6ea5ede9869e18d781e3fc1a8c3Lenny Maiorani
912bd1d16a1792cd6ea5ede9869e18d781e3fc1a8c3Lenny Maioranivoid strcasecmp_null_1() {
913bd1d16a1792cd6ea5ede9869e18d781e3fc1a8c3Lenny Maiorani  char *x = "123";
914bd1d16a1792cd6ea5ede9869e18d781e3fc1a8c3Lenny Maiorani  char *y = NULL;
9159e49d9fbdc861c25c2480233147dee07f5fa9660Jordy Rose  strcasecmp(x, y); // expected-warning{{Null pointer argument in call to string comparison function}}
916bd1d16a1792cd6ea5ede9869e18d781e3fc1a8c3Lenny Maiorani}
917bd1d16a1792cd6ea5ede9869e18d781e3fc1a8c3Lenny Maiorani
918bd1d16a1792cd6ea5ede9869e18d781e3fc1a8c3Lenny Maioranivoid strcasecmp_diff_length_0() {
919bd1d16a1792cd6ea5ede9869e18d781e3fc1a8c3Lenny Maiorani  char *x = "abcde";
920bd1d16a1792cd6ea5ede9869e18d781e3fc1a8c3Lenny Maiorani  char *y = "aBd";
92143d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose  clang_analyzer_eval(strcasecmp(x, y) == -1); // expected-warning{{TRUE}}
922bd1d16a1792cd6ea5ede9869e18d781e3fc1a8c3Lenny Maiorani}
923bd1d16a1792cd6ea5ede9869e18d781e3fc1a8c3Lenny Maiorani
924bd1d16a1792cd6ea5ede9869e18d781e3fc1a8c3Lenny Maioranivoid strcasecmp_diff_length_1() {
925bd1d16a1792cd6ea5ede9869e18d781e3fc1a8c3Lenny Maiorani  char *x = "abc";
926bd1d16a1792cd6ea5ede9869e18d781e3fc1a8c3Lenny Maiorani  char *y = "aBdef";
92743d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose  clang_analyzer_eval(strcasecmp(x, y) == -1); // expected-warning{{TRUE}}
928bd1d16a1792cd6ea5ede9869e18d781e3fc1a8c3Lenny Maiorani}
929bd1d16a1792cd6ea5ede9869e18d781e3fc1a8c3Lenny Maiorani
930bd1d16a1792cd6ea5ede9869e18d781e3fc1a8c3Lenny Maioranivoid strcasecmp_diff_length_2() {
931bd1d16a1792cd6ea5ede9869e18d781e3fc1a8c3Lenny Maiorani  char *x = "aBcDe";
932bd1d16a1792cd6ea5ede9869e18d781e3fc1a8c3Lenny Maiorani  char *y = "abc";
93343d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose  clang_analyzer_eval(strcasecmp(x, y) == 1); // expected-warning{{TRUE}}
934bd1d16a1792cd6ea5ede9869e18d781e3fc1a8c3Lenny Maiorani}
935bd1d16a1792cd6ea5ede9869e18d781e3fc1a8c3Lenny Maiorani
936bd1d16a1792cd6ea5ede9869e18d781e3fc1a8c3Lenny Maioranivoid strcasecmp_diff_length_3() {
937bd1d16a1792cd6ea5ede9869e18d781e3fc1a8c3Lenny Maiorani  char *x = "aBc";
938bd1d16a1792cd6ea5ede9869e18d781e3fc1a8c3Lenny Maiorani  char *y = "abcde";
93943d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose  clang_analyzer_eval(strcasecmp(x, y) == -1); // expected-warning{{TRUE}}
940bd1d16a1792cd6ea5ede9869e18d781e3fc1a8c3Lenny Maiorani}
941454fd2d3a1b6d0ef225c5d3927c1ad3b97510d1aLenny Maiorani
942adc42d412d747391dbcee234610f00b0f087cf7bJordy Rosevoid strcasecmp_embedded_null () {
94343d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose	clang_analyzer_eval(strcasecmp("ab\0zz", "ab\0yy") == 0); // expected-warning{{TRUE}}
944adc42d412d747391dbcee234610f00b0f087cf7bJordy Rose}
945adc42d412d747391dbcee234610f00b0f087cf7bJordy Rose
946454fd2d3a1b6d0ef225c5d3927c1ad3b97510d1aLenny Maiorani//===----------------------------------------------------------------------===
947454fd2d3a1b6d0ef225c5d3927c1ad3b97510d1aLenny Maiorani// strncasecmp()
948454fd2d3a1b6d0ef225c5d3927c1ad3b97510d1aLenny Maiorani//===----------------------------------------------------------------------===
949454fd2d3a1b6d0ef225c5d3927c1ad3b97510d1aLenny Maiorani
950454fd2d3a1b6d0ef225c5d3927c1ad3b97510d1aLenny Maiorani#define strncasecmp BUILTIN(strncasecmp)
951adc42d412d747391dbcee234610f00b0f087cf7bJordy Roseint strncasecmp(const char *s1, const char *s2, size_t n);
952454fd2d3a1b6d0ef225c5d3927c1ad3b97510d1aLenny Maiorani
953454fd2d3a1b6d0ef225c5d3927c1ad3b97510d1aLenny Maioranivoid strncasecmp_constant0() {
95443d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose  clang_analyzer_eval(strncasecmp("abc", "Abc", 3) == 0); // expected-warning{{TRUE}}
955454fd2d3a1b6d0ef225c5d3927c1ad3b97510d1aLenny Maiorani}
956454fd2d3a1b6d0ef225c5d3927c1ad3b97510d1aLenny Maiorani
957454fd2d3a1b6d0ef225c5d3927c1ad3b97510d1aLenny Maioranivoid strncasecmp_constant_and_var_0() {
958454fd2d3a1b6d0ef225c5d3927c1ad3b97510d1aLenny Maiorani  char *x = "abc";
95943d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose  clang_analyzer_eval(strncasecmp(x, "Abc", 3) == 0); // expected-warning{{TRUE}}
960454fd2d3a1b6d0ef225c5d3927c1ad3b97510d1aLenny Maiorani}
961454fd2d3a1b6d0ef225c5d3927c1ad3b97510d1aLenny Maiorani
962454fd2d3a1b6d0ef225c5d3927c1ad3b97510d1aLenny Maioranivoid strncasecmp_constant_and_var_1() {
963454fd2d3a1b6d0ef225c5d3927c1ad3b97510d1aLenny Maiorani  char *x = "abc";
96443d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose  clang_analyzer_eval(strncasecmp("Abc", x, 3) == 0); // expected-warning{{TRUE}}
965454fd2d3a1b6d0ef225c5d3927c1ad3b97510d1aLenny Maiorani}
966454fd2d3a1b6d0ef225c5d3927c1ad3b97510d1aLenny Maiorani
967454fd2d3a1b6d0ef225c5d3927c1ad3b97510d1aLenny Maioranivoid strncasecmp_0() {
968454fd2d3a1b6d0ef225c5d3927c1ad3b97510d1aLenny Maiorani  char *x = "abc";
969454fd2d3a1b6d0ef225c5d3927c1ad3b97510d1aLenny Maiorani  char *y = "Abc";
97043d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose  clang_analyzer_eval(strncasecmp(x, y, 3) == 0); // expected-warning{{TRUE}}
971454fd2d3a1b6d0ef225c5d3927c1ad3b97510d1aLenny Maiorani}
972454fd2d3a1b6d0ef225c5d3927c1ad3b97510d1aLenny Maiorani
973454fd2d3a1b6d0ef225c5d3927c1ad3b97510d1aLenny Maioranivoid strncasecmp_1() {
974454fd2d3a1b6d0ef225c5d3927c1ad3b97510d1aLenny Maiorani  char *x = "Bcd";
975454fd2d3a1b6d0ef225c5d3927c1ad3b97510d1aLenny Maiorani  char *y = "abc";
97643d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose  clang_analyzer_eval(strncasecmp(x, y, 3) == 1); // expected-warning{{TRUE}}
977454fd2d3a1b6d0ef225c5d3927c1ad3b97510d1aLenny Maiorani}
978454fd2d3a1b6d0ef225c5d3927c1ad3b97510d1aLenny Maiorani
979454fd2d3a1b6d0ef225c5d3927c1ad3b97510d1aLenny Maioranivoid strncasecmp_2() {
980454fd2d3a1b6d0ef225c5d3927c1ad3b97510d1aLenny Maiorani  char *x = "abc";
981454fd2d3a1b6d0ef225c5d3927c1ad3b97510d1aLenny Maiorani  char *y = "Bcd";
98243d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose  clang_analyzer_eval(strncasecmp(x, y, 3) == -1); // expected-warning{{TRUE}}
983454fd2d3a1b6d0ef225c5d3927c1ad3b97510d1aLenny Maiorani}
984454fd2d3a1b6d0ef225c5d3927c1ad3b97510d1aLenny Maiorani
985454fd2d3a1b6d0ef225c5d3927c1ad3b97510d1aLenny Maioranivoid strncasecmp_null_0() {
986454fd2d3a1b6d0ef225c5d3927c1ad3b97510d1aLenny Maiorani  char *x = NULL;
987454fd2d3a1b6d0ef225c5d3927c1ad3b97510d1aLenny Maiorani  char *y = "123";
9889e49d9fbdc861c25c2480233147dee07f5fa9660Jordy Rose  strncasecmp(x, y, 3); // expected-warning{{Null pointer argument in call to string comparison function}}
989454fd2d3a1b6d0ef225c5d3927c1ad3b97510d1aLenny Maiorani}
990454fd2d3a1b6d0ef225c5d3927c1ad3b97510d1aLenny Maiorani
991454fd2d3a1b6d0ef225c5d3927c1ad3b97510d1aLenny Maioranivoid strncasecmp_null_1() {
992454fd2d3a1b6d0ef225c5d3927c1ad3b97510d1aLenny Maiorani  char *x = "123";
993454fd2d3a1b6d0ef225c5d3927c1ad3b97510d1aLenny Maiorani  char *y = NULL;
9949e49d9fbdc861c25c2480233147dee07f5fa9660Jordy Rose  strncasecmp(x, y, 3); // expected-warning{{Null pointer argument in call to string comparison function}}
995454fd2d3a1b6d0ef225c5d3927c1ad3b97510d1aLenny Maiorani}
996454fd2d3a1b6d0ef225c5d3927c1ad3b97510d1aLenny Maiorani
997454fd2d3a1b6d0ef225c5d3927c1ad3b97510d1aLenny Maioranivoid strncasecmp_diff_length_0() {
998454fd2d3a1b6d0ef225c5d3927c1ad3b97510d1aLenny Maiorani  char *x = "abcde";
999454fd2d3a1b6d0ef225c5d3927c1ad3b97510d1aLenny Maiorani  char *y = "aBd";
100043d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose  clang_analyzer_eval(strncasecmp(x, y, 5) == -1); // expected-warning{{TRUE}}
1001454fd2d3a1b6d0ef225c5d3927c1ad3b97510d1aLenny Maiorani}
1002454fd2d3a1b6d0ef225c5d3927c1ad3b97510d1aLenny Maiorani
1003454fd2d3a1b6d0ef225c5d3927c1ad3b97510d1aLenny Maioranivoid strncasecmp_diff_length_1() {
1004454fd2d3a1b6d0ef225c5d3927c1ad3b97510d1aLenny Maiorani  char *x = "abc";
1005454fd2d3a1b6d0ef225c5d3927c1ad3b97510d1aLenny Maiorani  char *y = "aBdef";
100643d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose  clang_analyzer_eval(strncasecmp(x, y, 5) == -1); // expected-warning{{TRUE}}
1007454fd2d3a1b6d0ef225c5d3927c1ad3b97510d1aLenny Maiorani}
1008454fd2d3a1b6d0ef225c5d3927c1ad3b97510d1aLenny Maiorani
1009454fd2d3a1b6d0ef225c5d3927c1ad3b97510d1aLenny Maioranivoid strncasecmp_diff_length_2() {
1010454fd2d3a1b6d0ef225c5d3927c1ad3b97510d1aLenny Maiorani  char *x = "aBcDe";
1011454fd2d3a1b6d0ef225c5d3927c1ad3b97510d1aLenny Maiorani  char *y = "abc";
101243d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose  clang_analyzer_eval(strncasecmp(x, y, 5) == 1); // expected-warning{{TRUE}}
1013454fd2d3a1b6d0ef225c5d3927c1ad3b97510d1aLenny Maiorani}
1014454fd2d3a1b6d0ef225c5d3927c1ad3b97510d1aLenny Maiorani
1015454fd2d3a1b6d0ef225c5d3927c1ad3b97510d1aLenny Maioranivoid strncasecmp_diff_length_3() {
1016454fd2d3a1b6d0ef225c5d3927c1ad3b97510d1aLenny Maiorani  char *x = "aBc";
1017454fd2d3a1b6d0ef225c5d3927c1ad3b97510d1aLenny Maiorani  char *y = "abcde";
101843d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose  clang_analyzer_eval(strncasecmp(x, y, 5) == -1); // expected-warning{{TRUE}}
1019454fd2d3a1b6d0ef225c5d3927c1ad3b97510d1aLenny Maiorani}
1020454fd2d3a1b6d0ef225c5d3927c1ad3b97510d1aLenny Maiorani
1021454fd2d3a1b6d0ef225c5d3927c1ad3b97510d1aLenny Maioranivoid strncasecmp_diff_length_4() {
1022454fd2d3a1b6d0ef225c5d3927c1ad3b97510d1aLenny Maiorani  char *x = "abcde";
1023454fd2d3a1b6d0ef225c5d3927c1ad3b97510d1aLenny Maiorani  char *y = "aBc";
102443d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose  clang_analyzer_eval(strncasecmp(x, y, 3) == 0); // expected-warning{{TRUE}}
1025454fd2d3a1b6d0ef225c5d3927c1ad3b97510d1aLenny Maiorani}
1026454fd2d3a1b6d0ef225c5d3927c1ad3b97510d1aLenny Maiorani
1027454fd2d3a1b6d0ef225c5d3927c1ad3b97510d1aLenny Maioranivoid strncasecmp_diff_length_5() {
1028454fd2d3a1b6d0ef225c5d3927c1ad3b97510d1aLenny Maiorani  char *x = "abcde";
1029454fd2d3a1b6d0ef225c5d3927c1ad3b97510d1aLenny Maiorani  char *y = "aBd";
103043d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose  clang_analyzer_eval(strncasecmp(x, y, 3) == -1); // expected-warning{{TRUE}}
1031454fd2d3a1b6d0ef225c5d3927c1ad3b97510d1aLenny Maiorani}
1032454fd2d3a1b6d0ef225c5d3927c1ad3b97510d1aLenny Maiorani
1033454fd2d3a1b6d0ef225c5d3927c1ad3b97510d1aLenny Maioranivoid strncasecmp_diff_length_6() {
1034454fd2d3a1b6d0ef225c5d3927c1ad3b97510d1aLenny Maiorani  char *x = "aBDe";
1035454fd2d3a1b6d0ef225c5d3927c1ad3b97510d1aLenny Maiorani  char *y = "abc";
103643d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose  clang_analyzer_eval(strncasecmp(x, y, 3) == 1); // expected-warning{{TRUE}}
1037454fd2d3a1b6d0ef225c5d3927c1ad3b97510d1aLenny Maiorani}
1038adc42d412d747391dbcee234610f00b0f087cf7bJordy Rose
1039adc42d412d747391dbcee234610f00b0f087cf7bJordy Rosevoid strncasecmp_embedded_null () {
104043d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose	clang_analyzer_eval(strncasecmp("ab\0zz", "ab\0yy", 4) == 0); // expected-warning{{TRUE}}
1041adc42d412d747391dbcee234610f00b0f087cf7bJordy Rose}
1042