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.
This commit is contained in:
djcb
2016-11-16 20:23:03 +02:00
parent d30e0ab2ba
commit 98505aa23b

View File

@ -434,7 +434,6 @@ gboolean
mu_util_fputs_encoded (const char *str, FILE *stream) mu_util_fputs_encoded (const char *str, FILE *stream)
{ {
int rv; int rv;
unsigned bytes;
char *conv; char *conv;
g_return_val_if_fail (stream, FALSE); g_return_val_if_fail (stream, FALSE);
@ -443,23 +442,15 @@ mu_util_fputs_encoded (const char *str, FILE *stream)
if (mu_util_locale_is_utf8()) if (mu_util_locale_is_utf8())
return fputs (str, stream) == EOF ? FALSE : TRUE; return fputs (str, stream) == EOF ? FALSE : TRUE;
/* charset is _not_ utf8, so we actually have to convert /* charset is _not_ utf8, so we need to convert it */
* it
*/
conv = NULL; conv = NULL;
if (g_utf8_validate (str, -1, NULL)) if (g_utf8_validate (str, -1, NULL))
/* it _seems_ that on the bsds, the final err param conv = g_locale_from_utf8 (str, -1, NULL, NULL, NULL);
* may receive garbage... so we don't use it */
conv = g_locale_from_utf8
(str, -1, (gsize*)&bytes, 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");
/* 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; rv = conv ? fputs (conv, stream) : EOF;
g_free (conv); g_free (conv);