brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.9 KiB · c3e5021 Raw
44 lines · cpp
1// RUN: %check_clang_tidy %s bugprone-unchecked-string-to-number-conversion %t2 3typedef void *             FILE;4 5extern FILE *stdin;6 7extern int fscanf(FILE * stream, const char * format, ...);8extern int sscanf(const char * s, const char * format, ...);9 10extern double atof(const char *nptr);11extern int atoi(const char *nptr);12extern long int atol(const char *nptr);13extern long long int atoll(const char *nptr);14 15namespace std {16using ::FILE; using ::stdin;17using ::fscanf; using ::sscanf;18using ::atof; using ::atoi; using ::atol; using ::atoll;19}20 21void 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' instead26  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' instead28  std::fscanf(std::stdin, "%lld", &ll);29}30 31void 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' instead33  int i = std::atoi(in); // to int34  // 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' instead35  long l = std::atol(in); // to long36 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' instead40  long long ll = atoll(in); // to long long41  // 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' instead42  double d = atof(in); // to double43}44