public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug string/31365] New: wcsftime produces invalid characters when the time's weekday or month is out-of-range
@ 2024-02-09 22:05 bruno at clisp dot org
  2024-02-09 22:06 ` [Bug string/31365] " bruno at clisp dot org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: bruno at clisp dot org @ 2024-02-09 22:05 UTC (permalink / raw)
  To: glibc-bugs

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.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug string/31365] wcsftime produces invalid characters when the time's weekday or month is out-of-range
  2024-02-09 22:05 [Bug string/31365] New: wcsftime produces invalid characters when the time's weekday or month is out-of-range bruno at clisp dot org
@ 2024-02-09 22:06 ` 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
  2 siblings, 0 replies; 4+ messages in thread
From: bruno at clisp dot org @ 2024-02-09 22:06 UTC (permalink / raw)
  To: glibc-bugs

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

Bruno Haible <bruno at clisp dot org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
               Host|                            |sparc64-unknown-linux-gnu

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug string/31365] wcsftime produces invalid characters when the time's weekday or month is out-of-range
  2024-02-09 22:05 [Bug string/31365] New: wcsftime produces invalid characters when the time's weekday or month is out-of-range bruno at clisp dot org
  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
  2 siblings, 0 replies; 4+ messages in thread
From: bruno at clisp dot org @ 2024-02-09 22:12 UTC (permalink / raw)
  To: glibc-bugs

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

--- Comment #1 from Bruno Haible <bruno at clisp dot org> ---
Created attachment 15356
  --> https://sourceware.org/bugzilla/attachment.cgi?id=15356&action=edit
proposed fix

Find attached a proposed fix (untested, but quite obvious).

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug string/31365] wcsftime produces invalid characters when the time's weekday or month is out-of-range
  2024-02-09 22:05 [Bug string/31365] New: wcsftime produces invalid characters when the time's weekday or month is out-of-range bruno at clisp dot org
  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
  2 siblings, 0 replies; 4+ messages in thread
From: matoro_bugzilla_glibc at matoro dot tk @ 2024-02-09 22:34 UTC (permalink / raw)
  To: glibc-bugs

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

matoro <matoro_bugzilla_glibc at matoro dot tk> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |matoro_bugzilla_glibc@mator
                   |                            |o.tk

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-02-09 22:34 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-09 22:05 [Bug string/31365] New: wcsftime produces invalid characters when the time's weekday or month is out-of-range bruno at clisp dot org
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

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).