bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: new module suggestion: fprintftime-check


From: Assaf Gordon
Subject: Re: new module suggestion: fprintftime-check
Date: Fri, 28 Dec 2018 13:09:58 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.3.0

Hello Bruno,

On 2018-12-28 9:34 a.m., Bruno Haible wrote:
This function enables syntax-check of the format string.

First question: Should this syntax-check be integrated into the
nstrftime() and fprintftime() functions? These functions are gnulib
inventions, therefore they could be extended to return
   - an error indicator (maybe EINVAL?),
   - a detailed error message, if you like,
   - a pointer to the wrong directive in the format string, if you like.
Or is it better to have a function that does only the syntax check,
and document that nstrftime() and fprintftime() should only be called
after the syntax check has been done?
(I have no preference. Just asking.)

Both nstrtime and fprintftime silently ignore bad formats:
https://git.savannah.gnu.org/cgit/gnulib.git/tree/lib/nstrftime.c#n1478

The comment even says:
      /* Unknown format; output the format, including the '%',
         since this is most likely the right thing to do if a
         multibyte string has been misparsed.  */

This has been the case since 1996 when strftime.c was imported from libc
(gnulib commit afabd949).

I suspect that changing this behavior would be a disruptive
backwards-incompatible change (but other opinions are welcomed).


I'd like to suggest the following new module: fprintftime-check.

For a module that does only the syntax check, I would suggest a
different name:
   - The prefix 'fprint' indicates output to a 'FILE *'.
   - The prefix 'str' indicates output to a 'char *' buffer.
Why not call it 'ftime-check' or 'check-ftime'?

Good idea. I'll change it.


tzalloc() may fail and return NULL. (And why would parsing the format
string be dependent on a particular time zone at all?)

nstrtime's __strftime_internal() is a complicated beast, I don't
claim to fully understand it.
But the function contains this comment:
   /* POSIX.1 requires that local time zone information be used as
     though strftime called tzset.  */
https://git.savannah.gnu.org/cgit/gnulib.git/tree/lib/nstrftime.c#n540

And there is even an output "bool * tzset_called" parameter, to
let the caller know if it has been called or not - so I assume it is
critical to correct behavior of both nstrtime and fprintftime.
I will try to see if it can be disabled for the syntax-check code.

-assaf




reply via email to

[Prev in Thread] Current Thread [Next in Thread]