mirror of
https://github.com/github/codeql.git
synced 2025-12-16 16:53:25 +01:00
Fixed error in gmtime example
gmtime and gmtime_r take a time_t pointer, so have to store the value of time(NULL) on the stack. Signed-off-by: Ole Herman Schumacher Elgesem <oleherman93@gmail.com>
This commit is contained in:
@@ -1,12 +1,14 @@
|
||||
// BAD: using gmtime
|
||||
int is_morning_bad() {
|
||||
struct tm *now = gmtime(time(NULL));
|
||||
const time_t now_seconds = time(NULL);
|
||||
struct tm *now = gmtime(&now_seconds);
|
||||
return (now->tm_hour < 12);
|
||||
}
|
||||
|
||||
// GOOD: using gmtime_r
|
||||
int is_morning_good() {
|
||||
const time_t now_seconds = time(NULL);
|
||||
struct tm now;
|
||||
gmtime_r(time(NULL), &now);
|
||||
gmtime_r(&now_seconds, &now);
|
||||
return (now.tm_hour < 12);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user