diff options
author | Eric Curtin <ericcurtin17@gmail.com> | 2020-03-05 10:59:02 +0000 |
---|---|---|
committer | Eric Curtin <ericcurtin17@gmail.com> | 2020-03-05 10:59:02 +0000 |
commit | aa125f511d1407176933d0b447dacb4125382b9d (patch) | |
tree | 7736c20dccd72c56d5d1cc53b2c6fa2de7c1b237 | |
parent | d222aa9a8e1df279e2c1bcf3608ac43ab706763d (diff) | |
download | inotify-tools-aa125f511d1407176933d0b447dacb4125382b9d.zip inotify-tools-aa125f511d1407176933d0b447dacb4125382b9d.tar.gz inotify-tools-aa125f511d1407176933d0b447dacb4125382b9d.tar.bz2 |
Use localtime_r over localtime
LGTM regards this unsafe as it isn't threadsafe, tools like tsan would
show this too. Now that shouldn't matter to us, but if it's available
on all platforms, it might future-proof us.
-rw-r--r-- | libinotifytools/src/inotifytools.c | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/libinotifytools/src/inotifytools.c b/libinotifytools/src/inotifytools.c index 33f9cf4..609f749 100644 --- a/libinotifytools/src/inotifytools.c +++ b/libinotifytools/src/inotifytools.c @@ -1840,10 +1840,9 @@ int inotifytools_snprintf( char * out, int size, static unsigned int i, ind; static char ch1; static char timestr[MAX_STRLEN]; - static time_t now; + static time_t now; - - if ( event->len > 0 ) { + if ( event->len > 0 ) { eventname = event->name; } else { @@ -1913,14 +1912,14 @@ int inotifytools_snprintf( char * out, int size, if ( ch1 == 'T' ) { if ( timefmt ) { - now = time(0); - if ( 0 >= strftime( timestr, MAX_STRLEN-1, timefmt, - localtime( &now ) ) ) { - - // time format probably invalid - error = EINVAL; - return ind; + struct tm now_tm; + if (0 >= strftime(timestr, MAX_STRLEN - 1, + timefmt, + localtime_r(&now, &now_tm))) { + // time format probably invalid + error = EINVAL; + return ind; } } else { |