From: Mike Hommey <mh@glandium.org>
To: git@vger.kernel.org
Cc: Johannes.Schindelin@gmx.de, Mike Hommey <mh@glandium.org>
Subject: [PATCH] Use mingw.h declarations for gmtime_r/localtime_r on msys2
Date: Tue, 5 Oct 2021 15:39:36 +0900 [thread overview]
Message-ID: <20211005063936.588874-1-mh@glandium.org> (raw)
Older versions of msys2 had _POSIX_THREAD_SAFE_FUNCTIONS set in
pthread_unistd.h, included from unistd.h. That would enable the
declarations for gmtime_r and localtime_r in time.h.
That's not the case anymore, and gmtime_r and localtime_r end up
being undeclared, which subsequently leads to "miscompilations", for
example, in datestamp(), where the result of localtime_r would be
truncated and sign-extended before being passed to tm_to_time_t, leading
to segfaults at runtime.
Signed-off-by: Mike Hommey <mh@glandium.org>
---
compat/mingw.h | 2 --
1 file changed, 2 deletions(-)
A possible alternative fix would be to e.g. add `#define _POSIX_C_SOURCE
200112L` to git-compat-util.h and add `ifndef __MINGW64_VERSION_MAJOR`
around the definitions of `gmtime_r` and `localtime_r` in
compat/mingw.c, since, after all, they are available there.
diff --git a/compat/mingw.h b/compat/mingw.h
index c9a52ad64a..4fd989980c 100644
--- a/compat/mingw.h
+++ b/compat/mingw.h
@@ -204,10 +204,8 @@ int pipe(int filedes[2]);
unsigned int sleep (unsigned int seconds);
int mkstemp(char *template);
int gettimeofday(struct timeval *tv, void *tz);
-#ifndef __MINGW64_VERSION_MAJOR
struct tm *gmtime_r(const time_t *timep, struct tm *result);
struct tm *localtime_r(const time_t *timep, struct tm *result);
-#endif
int getpagesize(void); /* defined in MinGW's libgcc.a */
struct passwd *getpwuid(uid_t uid);
int setitimer(int type, struct itimerval *in, struct itimerval *out);
--
2.33.0
next reply other threads:[~2021-10-05 6:55 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-05 6:39 Mike Hommey [this message]
2021-10-05 7:12 ` [PATCH] Use mingw.h declarations for gmtime_r/localtime_r on msys2 Carlo Arenas
2021-10-05 8:35 ` Mike Hommey
2021-11-18 3:02 ` Mike Hommey
2021-11-18 4:51 ` Carlo Arenas
2021-11-18 5:34 ` Mike Hommey
2021-11-18 7:58 ` Carlo Arenas
2021-11-18 9:05 ` Mike Hommey
2021-11-19 5:38 ` Carlo Arenas
2021-11-19 7:23 ` Mike Hommey
2021-11-19 9:36 ` Carlo Arenas
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20211005063936.588874-1-mh@glandium.org \
--to=mh@glandium.org \
--cc=Johannes.Schindelin@gmx.de \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).