1// RUN: %check_clang_tidy %s cert-err34-c %t
2
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' instead [cert-err34-c]
26 std::sscanf(s: in, format: "%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(stream: std::stdin, format: "%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' instead [cert-err34-c]
33 int i = std::atoi(nptr: 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(nptr: 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(nptr: 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(nptr: in); // to double
43}
44

source code of clang-tools-extra/test/clang-tidy/checkers/cert/err34-c.cpp