public inbox for cygwin-patches@cygwin.com
 help / color / mirror / Atom feed
From: Corinna Vinschen <corinna-cygwin@cygwin.com>
To: cygwin-patches@cygwin.com
Subject: Re: [PATCH] fix(libc): Fix handle of %E & %O modifiers at end of format string
Date: Mon, 13 Nov 2023 17:42:52 +0100	[thread overview]
Message-ID: <ZVJSDAyKK/h8bZa/@calimero.vinschen.de> (raw)
In-Reply-To: <ac7355c3-7b25-4410-94eb-9bd2f602f4ac@upm.es>

Hi Pedro,

On Nov 11 18:29, Pedro Luis Castedo Cepeda wrote:
> OK. It's not a newlib problem but a GLib one as it is relaying on common but
> non-standard strftime implementation details.
> 
> I attach a short program more focused in g_date_strftime implementation so
> it can be evaluated if it worths addressing this corner case.

Tricky.  I wonder what the GLib test is actually trying to accomplish.

POSIX has this to say:

  RETURN VALUE
    If the total number of resulting bytes including the  terminating
    null byte  is not more than maxsize, these functions shall return
    the number of bytes placed into the array pointed to by s, not
    including the  terminating NUL character. Otherwise, 0 shall be
    returned and the contents of the array are unspecified.

  ERRORS
    No errors are defined.

But, and that's the big problem, POSIX does *not* provide for the
error case, because it doesn't allow an error like using an incorrect
format string to occur.  Using an incorrect or undefined format code
is just not part of the standard.

And the Linux man page has an interesting extension to the above
POSIX RETURN VALUE section:

    Note  that  the  return value 0 does not necessarily indicate an
    error.  For example, in many locales %p yields an empty string.  An
    empty  format string will likewise yield an empty string.

and additionally in the BUGS section:

    If the output string would exceed max bytes, errno is  not  set.
    This makes it impossible to distinguish this error case from cases
    where the format  string  legitimately  produces  a  zero-length
    output  string.  POSIX.1-2001 does not specify any errno settings
    for strftime().

So the below case tested by GLib is entirely out of scope of the
standard.


Corinna

  reply	other threads:[~2023-11-13 16:42 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-09 19:04 Pedro Luis Castedo Cepeda
2023-11-10  6:17 ` Brian Inglis
2023-11-10 10:16   ` Corinna Vinschen
2023-11-10 17:44     ` Pedro Luis Castedo Cepeda
2023-11-11  5:57       ` Brian Inglis
2023-11-11 17:29         ` Pedro Luis Castedo Cepeda
2023-11-13 16:42           ` Corinna Vinschen [this message]
2023-11-13 18:46             ` Brian Inglis

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZVJSDAyKK/h8bZa/@calimero.vinschen.de \
    --to=corinna-cygwin@cygwin.com \
    --cc=cygwin-patches@cygwin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).