Re: [PATCH 1/1] Fix date checking in case if time was not initialized.

2 messages, 2 authors, 2016-06-15 · open the first message on its own page

Re: [PATCH 1/1] Fix date checking in case if time was not initialized.

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:56:15

Mike Gorchak [off-list ref] writes:
quoted
quoted
Fix is_date() function failings in detection of correct date in case
if time was not properly initialized.
Please explain why this patch is needed and what problem this patch
is trying to fix (if any) a bit better in the proposed log message.
For example, on what input do we call this function with partially
filled *r, and is that an error in the code, or is it an indication
that the input has only been consumed partially?
function is_date() must not fail if time fields are not set.
Currently is_date() invokes tm_to_time_t() which perform check of
time fields.  With these fixes t0006-date.sh test is no longer
fail on these tests:
The thing that puzzles me is that nobody reported that the following
fail on their platforms (and they do not fail for me on platforms I
have to test in my real/virtual boxes).
check_parse '2008-02-14 20:30:45' '2008-02-14 20:30:45 +0000'
check_parse '2008-02-14 20:30:45 -0500' '2008-02-14 20:30:45 -0500'
check_parse '2008-02-14 20:30:45 -0015' '2008-02-14 20:30:45 -0015'
check_parse '2008-02-14 20:30:45 -5' '2008-02-14 20:30:45 +0000'
check_parse '2008-02-14 20:30:45 -5:' '2008-02-14 20:30:45 +0000'
check_parse '2008-02-14 20:30:45 -05' '2008-02-14 20:30:45 -0500'
check_parse '2008-02-14 20:30:45 -:30' '2008-02-14 20:30:45 +0000'
check_parse '2008-02-14 20:30:45 -05:00' '2008-02-14 20:30:45 -0500'
So there must be something _else_ going on, and I cannot tell what
that something else is from your code change nor from the log
message.  I'd like to see that explained.

Still puzzled...

Re: [PATCH 1/1] Fix date checking in case if time was not initialized.

From: Mike Gorchak <hidden>
Date: 2016-06-15 22:56:15

The thing that puzzles me is that nobody reported that the following
fail on their platforms (and they do not fail for me on platforms I
have to test in my real/virtual boxes).
Ok, check_parse calls function parse_date(), it calls
parse_date_basic(), where following code is present:

	memset(&tm, 0, sizeof(tm));
	tm.tm_year = -1;
	tm.tm_mon = -1;
	tm.tm_mday = -1;
	tm.tm_isdst = -1;
	tm.tm_hour = -1;
	tm.tm_min = -1;
	tm.tm_sec = -1;

Almost all fields are set to -1. A bit later match_multi_number() is
called. It parses the date and calls is_date() with partially filled
tm structure, where all time fields: tm_hour, tm_min, tm_sec are set
to -1. tm_to_time_t() function is called by is_date() and has special
check:

	if (tm->tm_hour < 0 || tm->tm_min < 0 || tm->tm_sec < 0)
		return -1;

So is_date() always return negative result for the text string where
date is placed before time like '2008-02-14 20:30:45'. It must fail on
other platforms as well.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help