Skip to content

Commit 2937b57

Browse files
author
Зишан Мирза
committed
fix: tests for clang-tidy
1 parent 143450a commit 2937b57

File tree

1 file changed

+24
-14
lines changed

1 file changed

+24
-14
lines changed

clang-tools-extra/test/clang-tidy/checkers/bugprone/unsafe-functions.c

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -105,28 +105,38 @@ void f3(char *S, FILE *F) {
105105

106106
typedef int time_t;
107107
char *ctime(const time_t *Timer);
108-
struct tm *localtime(const struct tm *tm);
108+
struct tm *localtime(const time_t *Timer);
109109

110110
void f4(const time_t *Timer) {
111111
ctime(Timer);
112-
// CHECK-MESSAGES-WITH-ANNEX-K: :[[@LINE-1]]:3: warning: function 'ctime' is not bounds-checking and non-reentrant; 'ctime_s' should be used instead
113-
// CHECK-MESSAGES-WITH-ANNEX-K-CERT-ONLY: :[[@LINE-2]]:3: warning: function 'ctime' is not bounds-checking and non-reentrant; 'ctime_s' should be used instead
114-
// no-warning WITHOUT-ANNEX-K
112+
// CHECK-MESSAGES-WITH-ANNEX-K: :[[@LINE-1]]:116: warning: function 'ctime' is not bounds-checking and non-reentrant; 'ctime_s' should be used instead
113+
// CHECK-MESSAGES-WITH-ANNEX-K-CERT-ONLY: :[[@LINE-2]]:116: warning: function 'ctime' is not bounds-checking and non-reentrant; 'ctime_s' should be used instead
114+
// CHECK-MESSAGES-WITHOUT-ANNEX-K: :[[@LINE-3]]:116: warning: function 'ctime' is not bounds-checking and non-reentrant; 'strftime' should be used instead
115115

116116
localtime(Timer);
117-
// CHECK-MESSAGES-WITH-ANNEX-K: :[[@LINE-1]]:3: warning: function 'localtime' is not bounds-checking and non-reentrant; 'localtime_s' should be used instead
118-
// CHECK-MESSAGES-WITH-ANNEX-K-CERT-ONLY: :[[@LINE-2]]:3: warning: function 'localtime' is not bounds-checking and non-reentrant; 'localtime_s' should be used instead
119-
// no-warning WITHOUT-ANNEX-K
117+
// CHECK-MESSAGES-WITH-ANNEX-K: :[[@LINE-1]]:116: warning: function 'localtime' is not bounds-checking and non-reentrant; 'localtime_s' should be used instead
118+
// CHECK-MESSAGES-WITH-ANNEX-K-CERT-ONLY: :[[@LINE-2]]:116: warning: function 'localtime' is not bounds-checking and non-reentrant; 'localtime_s' should be used instead
119+
// CHECK-MESSAGES-WITHOUT-ANNEX-K: :[[@LINE-3]]:116: warning: function 'localtime' is not bounds-checking and non-reentrant; 'strftime' should be used instead
120+
121+
char *(*F1)(const time_t *) = ctime;
122+
// CHECK-MESSAGES-WITH-ANNEX-K: :[[@LINE-1]]:36: warning: function 'ctime' is not bounds-checking and non-reentrant; 'ctime_s' should be used instead
123+
// CHECK-MESSAGES-WITH-ANNEX-K-CERT-ONLY: :[[@LINE-2]]:36: warning: function 'ctime' is not bounds-checking and non-reentrant; 'ctime_s' should be used instead
124+
// CHECK-MESSAGES-WITHOUT-ANNEX-K: :[[@LINE-3]]:36: warning: function 'ctime' is not bounds-checking and non-reentrant; 'strftime' should be used instead
120125

121-
char *(*F1)(const struct tm *) = &ctime;
126+
char *(*F2)(const time_t *) = &ctime;
122127
// CHECK-MESSAGES-WITH-ANNEX-K: :[[@LINE-1]]:37: warning: function 'ctime' is not bounds-checking and non-reentrant; 'ctime_s' should be used instead
123128
// CHECK-MESSAGES-WITH-ANNEX-K-CERT-ONLY: :[[@LINE-2]]:37: warning: function 'ctime' is not bounds-checking and non-reentrant; 'ctime_s' should be used instead
124-
// no-warning WITHOUT-ANNEX-K
129+
// CHECK-MESSAGES-WITHOUT-ANNEX-K: :[[@LINE-3]]:37: warning: function 'ctime' is not bounds-checking and non-reentrant; 'strftime' should be used instead
130+
131+
struct tm *(*F4)(const time_t *) = localtime;
132+
// CHECK-MESSAGES-WITH-ANNEX-K: :[[@LINE-1]]:36: warning: function 'localtime' is not bounds-checking and non-reentrant; 'localtime_s' should be used instead
133+
// CHECK-MESSAGES-WITH-ANNEX-K-CERT-ONLY: :[[@LINE-2]]:36: warning: function 'localtime' is not bounds-checking and non-reentrant; 'localtime_s' should be used instead
134+
// CHECK-MESSAGES-WITHOUT-ANNEX-K: :[[@LINE-3]]:36: warning: function 'localtime' is not bounds-checking and non-reentrant; 'strftime' should be used instead
125135

126-
struct tm *(*F2)(const struct tm *) = &localtime;
136+
struct tm *(*F5)(const time_t *) = &localtime;
127137
// CHECK-MESSAGES-WITH-ANNEX-K: :[[@LINE-1]]:37: warning: function 'localtime' is not bounds-checking and non-reentrant; 'localtime_s' should be used instead
128138
// CHECK-MESSAGES-WITH-ANNEX-K-CERT-ONLY: :[[@LINE-2]]:37: warning: function 'localtime' is not bounds-checking and non-reentrant; 'localtime_s' should be used instead
129-
// no-warning WITHOUT-ANNEX-K
139+
// CHECK-MESSAGES-WITHOUT-ANNEX-K: :[[@LINE-3]]:37: warning: function 'localtime' is not bounds-checking and non-reentrant; 'strftime' should be used instead
130140
}
131141

132142
#define BUFSIZ 128
@@ -171,8 +181,8 @@ void fOptional() {
171181
typedef int errno_t;
172182
typedef size_t rsize_t;
173183
errno_t asctime_s(char *S, rsize_t Maxsize, const struct tm *TimePtr);
174-
errno_t ctime_s(char *S, rsize_t Maxsize, const struct tm *TimePtr);
175-
errno_t localtime_s(struct tm *TimePtr, time_t *Timep);
184+
errno_t ctime_s(char *S, rsize_t Maxsize, const time_t *Timep);
185+
errno_t localtime_s(const time_t *Timep, rsize_t Maxsize, const struct tm *TimePtr);
176186
errno_t strcat_s(char *S1, rsize_t S1Max, const char *S2);
177187

178188
void fUsingSafeFunctions(const struct tm *Time, FILE *F, time_t *Timep) {
@@ -187,7 +197,7 @@ void fUsingSafeFunctions(const struct tm *Time, FILE *F, time_t *Timep) {
187197
return;
188198

189199
// no-warning, safe function from annex K is used
190-
if (localtime_s(Time, Timep) != 0)
200+
if (localtime_s(Timep, BUFSIZ, Time) != 0)
191201
return;
192202

193203
// no-warning, safe function from annex K is used

0 commit comments

Comments
 (0)