threads / patch / 18750

patch64-bit fix for date.c.

Subject: [PATCH] 64-bit fix for date.c.

## tl;dr

7 messages between Apr 6, 2009 and May 6, 2009. Diffs are folded; open one to read it.

replies: 6people: 4as markdown or json

Bernd Ahlers· Apr 6, 2009, 17:26 UTC · lore
Hello!

This unbreaks the localtime_r call on OpenBSD/sparc64 and removes the following compiler warning.

"passing arg 1 of `localtime_r' from incompatible pointer type"
---
 date.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
Show changes to date.c +3 −1
diff --git a/date.c b/date.c
index 1165d30..409a17d 100644
--- a/date.c
+++ b/date.c
@@ -871,13 +871,15 @@ unsigned long approxidate(const char *date)
 	int number = 0;
 	struct tm tm, now;
 	struct timeval tv;
+	time_t time_sec;
 	char buffer[50];
 
 	if (parse_date(date, buffer, sizeof(buffer)) > 0)
 		return strtoul(buffer, NULL, 10);
 
 	gettimeofday(&tv, NULL);
-	localtime_r(&tv.tv_sec, &tm);
+	time_sec = tv.tv_sec;
+	localtime_r(&time_sec, &tm);
 	now = tm;
 	for (;;) {
 		unsigned char c = *date;
-- 
1.6.2.2
Jeff King· Apr 6, 2009, 19:06 UTC · re: Bernd Ahlers · lore

Re: [PATCH] 64-bit fix for date.c.

On Mon, Apr 06, 2009 at 07:26:37PM +0200, Bernd Ahlers wrote:
Show 8 quoted lines
> @@ -871,13 +871,15 @@ unsigned long approxidate(const char *date)
>  	struct timeval tv;
> +	time_t time_sec;
> [...]
>  	gettimeofday(&tv, NULL);
> -	localtime_r(&tv.tv_sec, &tm);
> +	time_sec = tv.tv_sec;
> +	localtime_r(&time_sec, &tm);

Hmph. According to POSIX, tv_sec _is_ a time_t. But I see on FreeBSD, also, it is actually a "long". So I think this fix makes sense.

-Peff
Bernd Ahlers· May 4, 2009, 14:26 UTC · re: Jeff King · lore

Re: [PATCH] 64-bit fix for date.c.

Jeff King [Mon, Apr 06, 2009 at 03:06:58PM -0400] wrote:
Show 14 quoted lines
>On Mon, Apr 06, 2009 at 07:26:37PM +0200, Bernd Ahlers wrote:
>
>> @@ -871,13 +871,15 @@ unsigned long approxidate(const char *date)
>>  	struct timeval tv;
>> +	time_t time_sec;
>> [...]
>>  	gettimeofday(&tv, NULL);
>> -	localtime_r(&tv.tv_sec, &tm);
>> +	time_sec = tv.tv_sec;
>> +	localtime_r(&time_sec, &tm);
>
>Hmph. According to POSIX, tv_sec _is_ a time_t. But I see on FreeBSD,
>also, it is actually a "long". So I think this fix makes sense.
>
Okay. So what's the next step to get this committed? :)
Bernd
Jeff King· May 4, 2009, 14:31 UTC · re: Bernd Ahlers · lore

Re: [PATCH] 64-bit fix for date.c.

On Mon, May 04, 2009 at 04:26:14PM +0200, Bernd Ahlers wrote:
Show 16 quoted lines
> Jeff King [Mon, Apr 06, 2009 at 03:06:58PM -0400] wrote:
> >On Mon, Apr 06, 2009 at 07:26:37PM +0200, Bernd Ahlers wrote:
> >
> >> @@ -871,13 +871,15 @@ unsigned long approxidate(const char *date)
> >>  	struct timeval tv;
> >> +	time_t time_sec;
> >> [...]
> >>  	gettimeofday(&tv, NULL);
> >> -	localtime_r(&tv.tv_sec, &tm);
> >> +	time_sec = tv.tv_sec;
> >> +	localtime_r(&time_sec, &tm);
> >
> >Hmph. According to POSIX, tv_sec _is_ a time_t. But I see on FreeBSD,
> >also, it is actually a "long". So I think this fix makes sense.
> >
> Okay. So what's the next step to get this committed? :)

Looks like Junio missed it the first time around, so re-send it to him, cc'ing the list. And you can add my

  Acked-by: Jeff King <peff@peff.net>
-Peff
Junio C Hamano· May 6, 2009, 05:51 UTC · re: Jeff King · lore

Re: [PATCH] 64-bit fix for date.c.

Jeff King <peff@peff.net> writes:
Show 23 quoted lines
> On Mon, May 04, 2009 at 04:26:14PM +0200, Bernd Ahlers wrote:
>
>> Jeff King [Mon, Apr 06, 2009 at 03:06:58PM -0400] wrote:
>> >On Mon, Apr 06, 2009 at 07:26:37PM +0200, Bernd Ahlers wrote:
>> >
>> >> @@ -871,13 +871,15 @@ unsigned long approxidate(const char *date)
>> >>  	struct timeval tv;
>> >> +	time_t time_sec;
>> >> [...]
>> >>  	gettimeofday(&tv, NULL);
>> >> -	localtime_r(&tv.tv_sec, &tm);
>> >> +	time_sec = tv.tv_sec;
>> >> +	localtime_r(&time_sec, &tm);
>> >
>> >Hmph. According to POSIX, tv_sec _is_ a time_t. But I see on FreeBSD,
>> >also, it is actually a "long". So I think this fix makes sense.
>> >
>> Okay. So what's the next step to get this committed? :)
>
> Looks like Junio missed it the first time around, so re-send it to him,
> cc'ing the list. And you can add my
>
>   Acked-by: Jeff King <peff@peff.net>
Thanks.
Tony Finch· May 6, 2009, 14:26 UTC · re: Junio C Hamano · lore

Re: [PATCH] 64-bit fix for date.c.

Jeff King [Mon, Apr 06, 2009 at 03:06:58PM -0400] wrote:
>
>Hmph. According to POSIX, tv_sec _is_ a time_t. But I see on FreeBSD,
>also, it is actually a "long". So I think this fix makes sense.
FreeBSD-7 has time_t tv_sec.
Tony.
-- 
f.anthony.n.finch  <dot@dotat.at>  http://dotat.at/
GERMAN BIGHT HUMBER: SOUTHWEST 5 TO 7. MODERATE OR ROUGH. SQUALLY SHOWERS.
MODERATE OR GOOD.
Jeff King· May 6, 2009, 16:49 UTC · re: Tony Finch · lore

Re: [PATCH] 64-bit fix for date.c.

On Wed, May 06, 2009 at 03:26:36PM +0100, Tony Finch wrote:
Show 6 quoted lines
> Jeff King [Mon, Apr 06, 2009 at 03:06:58PM -0400] wrote:
> >
> >Hmph. According to POSIX, tv_sec _is_ a time_t. But I see on FreeBSD,
> >also, it is actually a "long". So I think this fix makes sense.
> 
> FreeBSD-7 has time_t tv_sec.

Thanks for the data point (I had looked at FreeBSD 6). I think this fix still makes sense, though, as it should work on either type (and we need to support the older platforms, too).

-Peff

← back to recent threads