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:
@ -433,9 +433,8 @@ mu_util_locale_is_utf8 (void)
|
|||||||
gboolean
|
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,24 +442,16 @@ 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
|
/* conversion failed; this happens because is some cases GMime may gives
|
||||||
* may gives us non-UTF-8 strings from e.g. wrongly encoded
|
* us non-UTF-8 strings from e.g. wrongly encoded message-subjects; if
|
||||||
* message-subjects; if so, we escape the string
|
* so, we escape the string */
|
||||||
*/
|
conv = conv ? conv : g_strescape (str, "\n\t");
|
||||||
if (!conv)
|
rv = conv ? fputs (conv, stream) : EOF;
|
||||||
conv = g_strescape (str, "\n\t");
|
|
||||||
|
|
||||||
rv = conv ? fputs (conv, stream) : EOF;
|
|
||||||
g_free (conv);
|
g_free (conv);
|
||||||
|
|
||||||
return (rv == EOF) ? FALSE : TRUE;
|
return (rv == EOF) ? FALSE : TRUE;
|
||||||
|
|||||||
Reference in New Issue
Block a user