aboutsummaryrefslogtreecommitdiffstats
path: root/e-util
diff options
context:
space:
mode:
Diffstat (limited to 'e-util')
-rw-r--r--e-util/e-util.c46
1 files changed, 38 insertions, 8 deletions
diff --git a/e-util/e-util.c b/e-util/e-util.c
index 6f528d57ce..955151dcc5 100644
--- a/e-util/e-util.c
+++ b/e-util/e-util.c
@@ -771,10 +771,25 @@ size_t e_strftime(char *s, size_t max, const char *fmt, const struct tm *tm)
size_t
e_utf8_strftime(char *s, size_t max, const char *fmt, const struct tm *tm)
{
- size_t sz;
- char *locale_fmt = g_locale_from_utf8(fmt, -1, NULL, &sz, NULL);
- size_t ret = e_strftime(s, max, locale_fmt, tm);
- char *buf = g_locale_to_utf8(s, ret, NULL, &sz, NULL);
+ size_t sz, ret;
+ char *locale_fmt, *buf;
+
+ locale_fmt = g_locale_from_utf8(fmt, -1, NULL, &sz, NULL);
+ if (!locale_fmt)
+ return 0;
+
+ ret = e_strftime(s, max, locale_fmt, tm);
+ if (!ret) {
+ g_free (locale_fmt);
+ return 0;
+ }
+
+ buf = g_locale_to_utf8(s, ret, NULL, &sz, NULL);
+ if (!buf) {
+ g_free (locale_fmt);
+ return 0;
+ }
+
if (sz >= max) {
char *tmp = buf + max - 1;
tmp = g_utf8_find_prev_char(buf, tmp);
@@ -854,10 +869,25 @@ size_t e_strftime_fix_am_pm(char *s, size_t max, const char *fmt, const struct t
size_t
e_utf8_strftime_fix_am_pm(char *s, size_t max, const char *fmt, const struct tm *tm)
{
- size_t sz;
- char *locale_fmt = g_locale_from_utf8(fmt, -1, NULL, &sz, NULL);
- size_t ret = e_strftime_fix_am_pm(s, max, locale_fmt, tm);
- char *buf = g_locale_to_utf8(s, ret, NULL, &sz, NULL);
+ size_t sz, ret;
+ char *locale_fmt, *buf;
+
+ locale_fmt = g_locale_from_utf8(fmt, -1, NULL, &sz, NULL);
+ if (!locale_fmt)
+ return 0;
+
+ ret = e_strftime_fix_am_pm(s, max, locale_fmt, tm);
+ if (!ret) {
+ g_free (locale_fmt);
+ return 0;
+ }
+
+ buf = g_locale_to_utf8(s, ret, NULL, &sz, NULL);
+ if (!buf) {
+ g_free (locale_fmt);
+ return 0;
+ }
+
if (sz >= max) {
char *tmp = buf + max - 1;
tmp = g_utf8_find_prev_char(buf, tmp);