From: Petr Pisar <petr.pisar@atlas.cz>
To: musl@lists.openwall.com
Subject: [musl] strptime(s, "%Y-%j", &tm) does not update month and day
Date: Sat, 11 May 2024 17:24:59 +0200 [thread overview]
Message-ID: <Zj-Ny2wTG_PcMCd7@album.bayer.uni.cx> (raw)
[-- Attachment #1: Type: text/plain, Size: 1476 bytes --]
Hello,
When debugging a libisds test failure with musl-1.2.5
<https://bugs.gentoo.org/show_bug.cgi?id=928107>, I found that musl's
strptime() does not handle "%Y-%j" properly. It accepts the format, it parses
the input string, it returns a correct pointer past the input string, but it
does not update tm.tm_mon and tm.tm_mday fileds of the third argument.
A reproducer:
#define _XOPEN_SOURCE
#include <time.h>
#include <stdio.h>
#include <stddef.h>
int main(void) {
const char *input = "2001-34"; /* 34th day of 2001 year, i.e. 2001-02-03 */
struct tm time = {.tm_year=42, .tm_mon=42, .tm_mday=42, }; /* To detect changes */
char *ret = strptime(input, "%Y-%j", &time);
printf("Expected: ret=%p(%p+%td) tm_year=%d, tm_mon=%d, tm_mday=%d\n",
input + 7, input, (ptrdiff_t)7, 101, 1, 3);
printf("Got: ret=%p(%p+%td) tm_year=%d, tm_mon=%d, tm_mday=%d\n",
ret, input, ret - input, time.tm_year, time.tm_mon, time.tm_mday);
return 0;
}
$ gcc test.c && ./a.out
Expected: ret=0x560c1cd64007(0x560c1cd64000+7) tm_year=101, tm_mon=1, tm_mday=3
Got: ret=0x560c1cd64007(0x560c1cd64000+7) tm_year=101, tm_mon=42, tm_mday=42
Compare to glibc-2.38:
$ gcc test.c && ./a.out
Expected: ret=0x55fd94c4f00f(0x55fd94c4f008+7) tm_year=101, tm_mon=1, tm_mday=3
Got: ret=0x55fd94c4f00f(0x55fd94c4f008+7) tm_year=101, tm_mon=1, tm_mday=3
Tested on x86_64 platform with gcc-13.2.1_p20240210, binutils-2.42 and
musl-1.2.5
-- Petr
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next reply other threads:[~2024-05-11 15:25 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-11 15:24 Petr Pisar [this message]
2024-05-11 21:28 ` Rich Felker
2024-05-12 7:54 ` Petr Pisar
2024-05-13 12:18 ` Rich Felker
2024-05-13 21:18 ` Thorsten Glaser
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=Zj-Ny2wTG_PcMCd7@album.bayer.uni.cx \
--to=petr.pisar@atlas.cz \
--cc=musl@lists.openwall.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.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
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 NNTP newsgroup(s).