Skip to content

Commit

Permalink
strftime: Always restore LC_CTYPE locale
Browse files Browse the repository at this point in the history
my_strftime toggles LC_CTYPE to match LC_TIME to avoid mojibake.

In reading the code, I realized that there was a code path that doesn't
properly restore it, namely when failure is returned.  This commit fixes
that.
  • Loading branch information
khwilliamson committed May 7, 2023
1 parent 35a0358 commit dc2759a
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions locale.c
Expand Up @@ -7135,7 +7135,7 @@ S_strftime_tm(pTHX_ const char *fmt, const struct tm *mytm)
* indicates we have at least one byte of spare space (which will be
* used for the terminating NUL). */
if (inRANGE(len, 1, bufsize - 1)) {
goto strftime_success;
goto strftime_return;
}

/* There are several possible reasons for a 0 return code for a
Expand Down Expand Up @@ -7169,7 +7169,7 @@ S_strftime_tm(pTHX_ const char *fmt, const struct tm *mytm)
if (strEQ(fmt, "%p")) {
Renew(buf, 1, char);
*buf = '\0';
goto strftime_success;
goto strftime_return;
}

/* The other reason is that the format string is malformed. Probably it is
Expand All @@ -7178,9 +7178,9 @@ S_strftime_tm(pTHX_ const char *fmt, const struct tm *mytm)
* treated as a literal, but others may fail when '?' is illegal */
Safefree(buf);
SET_EINVAL;
return NULL;
buf = NULL;

strftime_success:
strftime_return:

# if defined(USE_LOCALE_CTYPE) && defined(USE_LOCALE_TIME)

Expand Down

0 comments on commit dc2759a

Please sign in to comment.