public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "bruno at clisp dot org" <sourceware-bugzilla@sourceware.org>
To: glibc-bugs@sourceware.org
Subject: [Bug string/31365] New: wcsftime produces invalid characters when the time's weekday or month is out-of-range
Date: Fri, 09 Feb 2024 22:05:42 +0000	[thread overview]
Message-ID: <bug-31365-131@http.sourceware.org/bugzilla/> (raw)

https://sourceware.org/bugzilla/show_bug.cgi?id=31365

            Bug ID: 31365
           Summary: wcsftime produces invalid characters when the time's
                    weekday or month is out-of-range
           Product: glibc
           Version: 2.38
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: string
          Assignee: unassigned at sourceware dot org
          Reporter: bruno at clisp dot org
  Target Milestone: ---

The wcsftime function is meant to produce, when the given time's weekday or
month is out-of-range, a result with question marks, like strftime does.

This works on little-endian platforms. But it does not work on big-endian
platforms.

How to reproduce: Compile and run this program.
================================ foo.c ==============================
#include <assert.h>
#include <errno.h>
#include <locale.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <wchar.h>

int main ()
{
  time_t t = 1509000003;
  struct tm *tm = gmtime (&t);
  wchar_t buf[100];
  size_t n;

  tm->tm_wday = -1;
  tm->tm_mon = -1;

  errno = 0;
  n = wcsftime (buf, sizeof buf / sizeof (wchar_t), L"|%a| %Y-%b-%d %H:%M:%S",
tm);
  if (n == 0)
    {
      perror ("wcsftime");
    }
  else
    {
      printf ("wcsftime output:\n");
      for (size_t i = 0; i < n; i++)
        printf ("U+0x%04x ", (unsigned int) buf[i]);
      printf ("\n");
      if (printf ("Converted to ASCII: %ls\n", buf) < 0)
        printf ("Conversion to ASCII failed.\n");
    }
}
=====================================================================

Output on ia64, ppc64le, riscv64, loongarch64:
---------------------------------------------------------------------
wcsftime output:
U+0x007c U+0x003f U+0x007c U+0x0020 U+0x0032 U+0x0030 U+0x0031 U+0x0037
U+0x002d U+0x003f U+0x002d U+0x0032 U+0x0036 U+0x0020 U+0x0030 U+0x0036
U+0x003a U+0x0034 U+0x0030 U+0x003a U+0x0030 U+0x0033 
Converted to ASCII: |?| 2017-?-26 06:40:03
---------------------------------------------------------------------

Output on mips64eb, powerpc64, sparc:
---------------------------------------------------------------------
wcsftime output:
U+0x007c U+0x3f000000 U+0x007c U+0x0020 U+0x0032 U+0x0030 U+0x0031 U+0x0037
U+0x002d U+0x3f000000 U+0x002d U+0x0032 U+0x0036 U+0x0020 U+0x0030 U+0x0036
U+0x003a U+0x0034 U+0x0030 U+0x003a U+0x0030 U+0x0033 
Conversion to ASCII failed.
---------------------------------------------------------------------

Output on hppa:
---------------------------------------------------------------------
wcsftime output:
U+0x007c U+0x3f000000 U+0x2e2e2f73 U+0x79736465 U+0x70732f75 U+0x6e69782f
U+0x73797376 U+0x2f6c696e U+0x75782f74 U+0x656c6c64 U+0x69722e63 U+0x007c
U+0x0020 U+0x0032 U+0x0030 U+0x0031 U+0x0037 U+0x002d U+0x3f000000 U+0x2e2e2f73
U+0x79736465 U+0x70732f75 U+0x6e69782f U+0x73797376 U+0x2f6c696e U+0x75782f74
U+0x656c6c64 U+0x69722e63 U+0x002d U+0x0032 U+0x0036 U+0x0020 U+0x0030 U+0x0036
U+0x003a U+0x0034 U+0x0030 U+0x003a U+0x0030 U+0x0033 
Conversion to ASCII failed.
---------------------------------------------------------------------

-- 
You are receiving this mail because:
You are on the CC list for the bug.

             reply	other threads:[~2024-02-09 22:05 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-09 22:05 bruno at clisp dot org [this message]
2024-02-09 22:06 ` [Bug string/31365] " bruno at clisp dot org
2024-02-09 22:12 ` bruno at clisp dot org
2024-02-09 22:34 ` matoro_bugzilla_glibc at matoro dot tk

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=bug-31365-131@http.sourceware.org/bugzilla/ \
    --to=sourceware-bugzilla@sourceware.org \
    --cc=glibc-bugs@sourceware.org \
    /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).