Skip to content

Commit

Permalink
banned.h: mark non-reentrant gmtime, etc as banned
Browse files Browse the repository at this point in the history
The traditional gmtime(), localtime(), ctime(), and asctime() functions
return pointers to shared storage. This means they're not thread-safe,
and they also run the risk of somebody holding onto the result across
multiple calls (where each call invalidates the previous result).

All callers should be using their reentrant counterparts.

Signed-off-by: Jeff King <peff@peff.net>
Reviewed-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
peff authored and gitster committed Dec 1, 2020
1 parent 72ffeb9 commit 1fbfdf5
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions banned.h
Expand Up @@ -29,4 +29,13 @@
#define vsprintf(buf,fmt,arg) BANNED(vsprintf)
#endif

#undef gmtime
#define gmtime(t) BANNED(gmtime)
#undef localtime
#define localtime(t) BANNED(localtime)
#undef ctime
#define ctime(t) BANNED(ctime)
#undef asctime
#define asctime(t) BANNED(asctime)

#endif /* BANNED_H */

0 comments on commit 1fbfdf5

Please sign in to comment.