[OpenAFS-devel] Re: [OpenAFS] vos: failed to parse date...

Jeffrey Hutzelman jhutz@cmu.edu
Fri, 31 Mar 2006 16:14:39 -0500


On Friday, March 31, 2006 09:27:01 AM -0500 Jim Rees <rees@umich.edu> wrote:

> I still don't see why the code is so complicated.  Can you think of any
> reason not to use a single scanf like I did for the 8601 method?

I think they're trying to be careful about rejecting invalid input.
Without the second sscanf, it would accept input like "2/22/2006,12:30"
but ignore the "12:30" part.

> 'c' is a local string of length two so I don't see how you could get
> scribbling.

Because the format string includes a %d for seconds with no corresponding 
input argument, so sscanf will try to store an integer at 'c'.  A string of 
length two is not big enough to receive an integer on most platforms.


>   This lacks sufficient validation; specifically, it doesn't include a
> dummy   field to tell if there was extra garbage at the end of the input.
>
> I didn't think that was necessary, but until it parses timezone info it's
> probably better to check for unexpected input.

Noting what I said above, I think it's rather important to check for 
unexpected input, rather than doing something different from what the user 
(or program) that invoked us intended.

-- Jeff