summaryrefslogtreecommitdiff
path: root/ref-filter.c
diff options
context:
space:
mode:
authorRené Scharfe <l.s.r@web.de>2024-04-05 17:44:59 (GMT)
committerJunio C Hamano <gitster@pobox.com>2024-04-05 22:21:14 (GMT)
commit9720d23e8caf4adee44b3a32803a9bb0480118bd (patch)
treed0f3b1b2362f4f492401ae87234c3f7ed6e81521 /ref-filter.c
parent1f49f7506f0d840e048ba78f7e0544c407568b58 (diff)
downloadgit-9720d23e8caf4adee44b3a32803a9bb0480118bd.zip
git-9720d23e8caf4adee44b3a32803a9bb0480118bd.tar.gz
git-9720d23e8caf4adee44b3a32803a9bb0480118bd.tar.bz2
date: make DATE_MODE thread-safe
date_mode_from_type() modifies a static variable and returns a pointer to it. This is not thread-safe. Most callers of date_mode_from_type() use it via the macro DATE_MODE and pass its result on to functions like show_date(), which take a const pointer and don't modify the struct. Avoid the static storage by putting the variable on the stack and returning the whole struct date_mode. Change functions that take a constant pointer to expect the whole struct instead. Reduce the cost of passing struct date_mode around on 64-bit systems by reordering its members to close the hole between the 32-bit wide .type and the 64-bit aligned .strftime_fmt as well as the alignment hole at the end. sizeof reports 24 before and 16 with this change on x64. Keep .type at the top to still allow initialization without designator -- though that's only done in a single location, in builtin/blame.c. Signed-off-by: René Scharfe <l.s.r@web.de> Acked-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'ref-filter.c')
-rw-r--r--ref-filter.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/ref-filter.c b/ref-filter.c
index 03542d0..59ad6f5 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -1627,7 +1627,7 @@ static void grab_date(const char *buf, struct atom_value *v, const char *atomnam
tz = strtol(zone, NULL, 10);
if ((tz == LONG_MIN || tz == LONG_MAX) && errno == ERANGE)
goto bad;
- v->s = xstrdup(show_date(timestamp, tz, &date_mode));
+ v->s = xstrdup(show_date(timestamp, tz, date_mode));
v->value = timestamp;
date_mode_release(&date_mode);
return;