diff options
author | Karl Williamson <khw@cpan.org> | 2014-06-06 13:04:55 -0600 |
---|---|---|
committer | Karl Williamson <khw@cpan.org> | 2014-06-07 10:24:58 -0600 |
commit | f406a44534fb208bbd0ef2f84f722d1693b498a4 (patch) | |
tree | fa5c322281bcb9cca640350f2b4483f93d601779 /ext | |
parent | 4874c8de0e9c2e6f771c454fd6122d32a42e42b6 (diff) | |
download | perl-f406a44534fb208bbd0ef2f84f722d1693b498a4.tar.gz |
PATCH: [perl #119425] strftime with %p
In a locale in which there is no a.m. nor p.m. indicator, a format with
only %p in it would print %p instead of nothing.
Diffstat (limited to 'ext')
-rw-r--r-- | ext/POSIX/POSIX.xs | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/ext/POSIX/POSIX.xs b/ext/POSIX/POSIX.xs index 085c06b115..797633406d 100644 --- a/ext/POSIX/POSIX.xs +++ b/ext/POSIX/POSIX.xs @@ -1737,6 +1737,7 @@ strftime(fmt, sec, min, hour, mday, mon, year, wday = -1, yday = -1, isdst = -1) CODE: { char *buf; + SV *sv; /* allowing user-supplied (rather than literal) formats * is normally frowned upon as a potential security risk; @@ -1744,14 +1745,23 @@ strftime(fmt, sec, min, hour, mday, mon, year, wday = -1, yday = -1, isdst = -1) GCC_DIAG_IGNORE(-Wformat-nonliteral); buf = my_strftime(SvPV_nolen(fmt), sec, min, hour, mday, mon, year, wday, yday, isdst); GCC_DIAG_RESTORE; + sv = sv_newmortal(); if (buf) { - SV *const sv = sv_newmortal(); sv_usepvn_flags(sv, buf, strlen(buf), SV_HAS_TRAILING_NUL); if (SvUTF8(fmt)) { SvUTF8_on(sv); } - ST(0) = sv; - } + } + else { /* We can't distinguish between errors and just an empty + * return; in all cases just return an empty string */ + SvUPGRADE(sv, SVt_PV); + SvPV_set(sv, (char *) ""); + SvPOK_on(sv); + SvCUR_set(sv, 0); + SvLEN_set(sv, 0); /* Won't attempt to free the string when sv + gets destroyed */ + } + ST(0) = sv; } void |