This is the mail archive of the cygwin-patches mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: winsup/cygwin/libc/strptime.cc(__strptime) strptime %F issue


On 2017-08-24 03:40, Corinna Vinschen wrote:
> On Aug 24 11:32, Corinna Vinschen wrote:
>> On Aug 23 13:25, Brian Inglis wrote:
>>> Cygwin strptime(3) (also strptime(1)) fails with default width, without an
>>> explicit width, because of the test in the following code:
>>>
>>> case 'F':	/* The date as "%Y-%m-%d". */
>>> 	{
>>> 	  LEGAL_ALT(0);
>>> 	  ymd |= SET_YMD;
>>> 	  char *tmp = __strptime ((const char *) bp, "%Y-%m-%d",
>>> 				  tm, era_info, alt_digits,
>>> 				  locale);
>>> 	  if (tmp && (uint) (tmp - (char *) bp) > width)
>>> 	    return NULL;
>>> 	  bp = (const unsigned char *) tmp;
>>> 	  continue;
>>> 	}
>>>
>>> as default width is zero so test fails and returns NULL.
>>>
>>> Simple patch for this as with the other cases supporting width is to change the
>>> test to:
>>>
>>> 	  if (tmp && width && (uint) (tmp - (char *) bp) > width)
>>>
>>> but this does not properly support [+0] flags or width in the format as
>>> specified by glibc (latest POSIX punts on %F) for compatibility with strftime(),
>>> affecting only the %Y format, supplying %[+0]<w-6>F, to support signed and zero
>>> filled fixed and variable length year fields in %F format.
>>
>> Ok, I admit I didn't understand this fully.  What is '<w-6>'?
>> Can you give a real world example?

Width prefix for %F minus six for "-mm-dd" to get the width for %Y.
Look at POSIX strftime %F handling
	http://pubs.opengroup.org/onlinepubs/9699919799/functions/strftime.html
or
	man 3p strftime | less +/\ F\
for what strftime allows and strptime should handle for symmetry and consistency.

>>> So do you want compatible support or just the quick fix?
>>
>> Quick and then right?  Fixing this in two steps is just as well.
> 
> Btw., FreeBSD's _strptime only calls _strptime recursively, without any
> checks for field width:
> 
>       case 'F':
> 	      buf = _strptime(buf, "%Y-%m-%d", tm, GMTp, locale);
> 	      if (buf == NULL)
> 		      return (NULL);
> 	      flags |= FLAG_MONTH | FLAG_MDAY | FLAG_YEAR;
> 	      break;

As did Cygwin, which just did a goto recurse, before it was changed to support
explicit width. Your call and option to go back and ignore it, patch bug, or
forward and support flags and width based on strftime documentation.

-- 
Take care. Thanks, Brian Inglis, Calgary, Alberta, Canada


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]