From 98505aa23b145a94f91528533c90b847cc0b6126 Mon Sep 17 00:00:00 2001 From: djcb Date: Wed, 16 Nov 2016 20:23:03 +0200 Subject: [PATCH] mu: fix mu_util_fputs_encode for non-utf8 mu_util_fputs_encode was aborting on behalf of the stack-guard on OpenBSD (seemingly only when compile with optimization). It appears as if the root cause of this was a differences in sizes of the parameters to g_locale_from_utf8. Fix this. --- lib/mu-util.c | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/lib/mu-util.c b/lib/mu-util.c index f79e87f4..13f45f2c 100644 --- a/lib/mu-util.c +++ b/lib/mu-util.c @@ -433,9 +433,8 @@ mu_util_locale_is_utf8 (void) gboolean mu_util_fputs_encoded (const char *str, FILE *stream) { - int rv; - unsigned bytes; - char *conv; + int rv; + char *conv; g_return_val_if_fail (stream, FALSE); @@ -443,24 +442,16 @@ mu_util_fputs_encoded (const char *str, FILE *stream) if (mu_util_locale_is_utf8()) return fputs (str, stream) == EOF ? FALSE : TRUE; - /* charset is _not_ utf8, so we actually have to convert - * it - */ + /* charset is _not_ utf8, so we need to convert it */ conv = NULL; if (g_utf8_validate (str, -1, NULL)) - /* it _seems_ that on the bsds, the final err param - * may receive garbage... so we don't use it */ - conv = g_locale_from_utf8 - (str, -1, (gsize*)&bytes, NULL, NULL); + conv = g_locale_from_utf8 (str, -1, NULL, NULL, NULL); - /* conversion failed; this happens because is some cases GMime - * may gives us non-UTF-8 strings from e.g. wrongly encoded - * message-subjects; if so, we escape the string - */ - if (!conv) - conv = g_strescape (str, "\n\t"); - - rv = conv ? fputs (conv, stream) : EOF; + /* conversion failed; this happens because is some cases GMime may gives + * us non-UTF-8 strings from e.g. wrongly encoded message-subjects; if + * so, we escape the string */ + conv = conv ? conv : g_strescape (str, "\n\t"); + rv = conv ? fputs (conv, stream) : EOF; g_free (conv); return (rv == EOF) ? FALSE : TRUE;