| 1 |
// RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin10 -disable-free -verify %s \ |
| 2 |
// RUN: -analyzer-checker=core,deadcode,optin.taint \ |
| 3 |
// RUN: -DERRNO_VAR |
| 4 |
|
| 5 |
// RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin10 -disable-free -verify %s \ |
| 6 |
// RUN: -analyzer-checker=core,deadcode,optin.taint \ |
| 7 |
// RUN: -DERRNO_FUNC |
| 8 |
|
| 9 |
// Note, we do need to include headers here, since the analyzer checks if the function declaration is located in a system header. |
| 10 |
// The errno value can be defined in multiple ways, test with each one. |
| 11 |
#ifdef ERRNO_VAR |
| 12 |
#include "Inputs/errno_var.h" |
| 13 |
#endif |
| 14 |
#ifdef ERRNO_FUNC |
| 15 |
#include "Inputs/errno_func.h" |
| 16 |
#endif |
| 17 |
#include "Inputs/system-header-simulator.h" |
| 18 |
|
| 19 |
|
| 20 |
void foo(void); |
| 21 |
|
| 22 |
// expected-no-diagnostics |
| 23 |
|
| 24 |
// Test errno gets invalidated by a system call. |
| 25 |
int testErrnoSystem(void) { |
| 26 |
int i; |
| 27 |
int *p = 0; |
| 28 |
fscanf(stdin, "%d", &i); |
| 29 |
if (errno == 0) { |
| 30 |
fscanf(stdin, "%d", &i); // errno gets invalidated here. |
| 31 |
return 5 / errno; // no-warning |
| 32 |
} |
| 33 |
|
| 34 |
errno = 0; |
| 35 |
fscanf(stdin, "%d", &i); // errno gets invalidated here. |
| 36 |
return 5 / errno; // no-warning |
| 37 |
} |
| 38 |
|
| 39 |
// Test that errno gets invalidated by internal calls. |
| 40 |
int testErrnoInternal(void) { |
| 41 |
int i; |
| 42 |
int *p = 0; |
| 43 |
fscanf(stdin, "%d", &i); |
| 44 |
if (errno == 0) { |
| 45 |
foo(); // errno gets invalidated here. |
| 46 |
return 5 / errno; // no-warning |
| 47 |
} |
| 48 |
return 0; |
| 49 |
} |