(translate_file): refactoring.

Allocate buffer only if charset converter is created successfully.
g_string_free() returns NULL if second argument is TRUE. Use that to get
rig of 'if' statement.
Reduce variable scope.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
Andrew Borodin 2022-02-23 18:49:17 +03:00
parent a6c142ed48
commit 5b4ec9b033

View File

@ -940,26 +940,20 @@ static void
translate_file (char *filedata)
{
GIConv conv;
GString *translated_data;
/* initial allocation for largest whole help file */
translated_data = g_string_sized_new (32 * 1024);
conv = str_crt_conv_from ("UTF-8");
if (conv == INVALID_CONV)
g_string_free (translated_data, TRUE);
else
if (conv != INVALID_CONV)
{
GString *translated_data;
gboolean nok;
g_free (fdata);
if (str_convert (conv, filedata, translated_data) != ESTR_FAILURE)
fdata = g_string_free (translated_data, FALSE);
else
{
fdata = NULL;
g_string_free (translated_data, TRUE);
}
/* initial allocation for largest whole help file */
translated_data = g_string_sized_new (32 * 1024);
nok = (str_convert (conv, filedata, translated_data) == ESTR_FAILURE);
fdata = g_string_free (translated_data, nok);
str_close_conv (conv);
}
}