Aaron Ballman | d744e63 | 2016-04-29 20:56:48 +0000 | [diff] [blame] | 1 | // RUN: %check_clang_tidy %s cert-err34-c %t -- -- -std=c++11 |
| 2 | |
| 3 | typedef void * FILE; |
| 4 | |
| 5 | extern FILE *stdin; |
| 6 | |
| 7 | extern int fscanf(FILE * stream, const char * format, ...); |
| 8 | extern int sscanf(const char * s, const char * format, ...); |
| 9 | |
| 10 | extern double atof(const char *nptr); |
| 11 | extern int atoi(const char *nptr); |
| 12 | extern long int atol(const char *nptr); |
| 13 | extern long long int atoll(const char *nptr); |
| 14 | |
| 15 | namespace std { |
| 16 | using ::FILE; using ::stdin; |
| 17 | using ::fscanf; using ::sscanf; |
| 18 | using ::atof; using ::atoi; using ::atol; using ::atoll; |
| 19 | } |
| 20 | |
| 21 | void f1(const char *in) { |
| 22 | int i; |
| 23 | long long ll; |
| 24 | |
| 25 | // CHECK-MESSAGES: :[[@LINE+1]]:3: warning: 'sscanf' used to convert a string to an integer value, but function will not report conversion errors; consider using 'strtol' instead [cert-err34-c] |
| 26 | std::sscanf(in, "%d", &i); |
| 27 | // CHECK-MESSAGES: :[[@LINE+1]]:3: warning: 'fscanf' used to convert a string to an integer value, but function will not report conversion errors; consider using 'strtoll' instead [cert-err34-c] |
| 28 | std::fscanf(std::stdin, "%lld", &ll); |
| 29 | } |
| 30 | |
| 31 | void f2(const char *in) { |
| 32 | // CHECK-MESSAGES: :[[@LINE+1]]:11: warning: 'atoi' used to convert a string to an integer value, but function will not report conversion errors; consider using 'strtol' instead [cert-err34-c] |
| 33 | int i = std::atoi(in); // to int |
| 34 | // CHECK-MESSAGES: :[[@LINE+1]]:12: warning: 'atol' used to convert a string to an integer value, but function will not report conversion errors; consider using 'strtol' instead [cert-err34-c] |
| 35 | long l = std::atol(in); // to long |
| 36 | |
| 37 | using namespace std; |
| 38 | |
| 39 | // CHECK-MESSAGES: :[[@LINE+1]]:18: warning: 'atoll' used to convert a string to an integer value, but function will not report conversion errors; consider using 'strtoll' instead [cert-err34-c] |
| 40 | long long ll = atoll(in); // to long long |
| 41 | // CHECK-MESSAGES: :[[@LINE+1]]:14: warning: 'atof' used to convert a string to a floating-point value, but function will not report conversion errors; consider using 'strtod' instead [cert-err34-c] |
| 42 | double d = atof(in); // to double |
| 43 | } |