mirror of https://github.com/djcb/mu.git
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:
parent
d30e0ab2ba
commit
98505aa23b
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue