summaryrefslogtreecommitdiff
path: root/util.c
diff options
context:
space:
mode:
authorKarl Williamson <khw@cpan.org>2022-12-20 09:38:50 -0700
committerKarl Williamson <khw@cpan.org>2023-01-05 19:57:29 -0700
commitfd0a8e29f81d64db5859309bc8bf0cd8e4950692 (patch)
tree4f611d71261c54e20526668ef61bea7b1db7b544 /util.c
parent7dda750e8a9686736d0aed7578ea6a8435aa4dd5 (diff)
downloadperl-fd0a8e29f81d64db5859309bc8bf0cd8e4950692.tar.gz
my_strftime: Test for trivial case before anything else
If the passed in format is the empty string, the result is going to also be the empty string. There is no need to do any other work.
Diffstat (limited to 'util.c')
-rw-r--r--util.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/util.c b/util.c
index 66a19bcac9..6e5ecd44fc 100644
--- a/util.c
+++ b/util.c
@@ -4095,6 +4095,14 @@ and LC_TIME are not the same locale.
*/
PERL_ARGS_ASSERT_MY_STRFTIME;
+ /* An empty format yields an empty result */
+ const int fmtlen = strlen(fmt);
+ if (fmtlen == 0) {
+ char *ret;
+ Newxz (ret, 1, char);
+ return ret;
+ }
+
/* Set mytm to now */
struct tm mytm;
init_tm(&mytm); /* XXX workaround - see init_tm() above */
@@ -4146,17 +4154,15 @@ and LC_TIME are not the same locale.
** indicate one of the following:
** 1. buffer overflowed,
** 2. illegal conversion specifier, or
- ** 3. the format string specifies nothing to be returned (which isn't an
- ** an error). This could be because the format is an empty string
- ** or it specifies %p which yields an empty string in some locales.
+ ** 3. the format string is %p which yields an empty string in some locales.
+ ** (which isn't an error).
** If there is a better way to make it portable, go ahead by
** all means.
*/
- if (inRANGE(len, 1, buflen - 1) || (len == 0 && *fmt == '\0'))
+ if (inRANGE(len, 1, buflen - 1))
return buf;
else {
/* Possibly buf overflowed - try again with a bigger buf */
- const int fmtlen = strlen(fmt);
int bufsize = fmtlen + buflen;
Renew(buf, bufsize, char);