|
|
Message-ID: <2419733.D4D8VRik6i@cagnes>
Date: Fri, 20 Nov 2026 15:46:25 +0100
From: Bruno Haible <bruno@...sp.org>
To: musl@...ts.openwall.com
Subject: getdate() returns invalid date
Hi,
POSIX:2024 specifies getdate() in
https://pubs.opengroup.org/onlinepubs/9799919799/functions/getdate.html
Among others, in the 4th example, last line of the table, it has an example
where
Line in template = %H:%M
Here's my test case:
$ cat datemsk
%m
%A %B %d, %Y, %H:%M:%S
%A
%B
%m/%d/%y %I %p
%d,%m,%Y %H:%M
%m/%d/%y
%d.%m.%y
%y-%m-%d
%A %H:%M:%S
%a
%b %a
%b %a %Y
%a %H
%b %H:%S
%H:%M
$ cat foo.c
#define _GNU_SOURCE 1
#include <time.h>
#include <stdio.h>
int
main ()
{
struct tm *t = getdate ("13:30");
if (t == NULL)
printf ("getdate failed\n");
else
{
char buf[100];
strftime (buf, sizeof (buf), "getdate returned %Y-%m-%d %H:%M:%S", t);
puts (buf);
}
}
Build and run it:
$ gcc -Wall foo.c
$ DATEMSK=`pwd`/datemsk ./a.out
Expected output:
getdate returned 2026-11-21 13:30:00
Actual output:
getdate returned 1900-14-13 13:30:00
Not only the year and the day field are wrong; also the month field is
out-of-range.
If I reduce 'datemsk' to a single line "%H:%M":
Expected output:
getdate returned 2026-11-21 13:30:00
Actual output:
getdate returned 1900-01-00 13:30:00
In this case the day field is out-of-range.
Seen in Alpine Linux 3.24 (i.e. musl 1.2.6-r3, according to [1]).
Bruno
[1] https://pkgs.alpinelinux.org/packages?name=musl&branch=v3.24&repo=&arch=x86_64&origin=&flagged=&maintainer=
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.