From: wwp Date: Thu, 30 Aug 2018 06:29:30 +0000 (+0200) Subject: Fix wrong logics leading to writing possibly broken config file, X-Git-Tag: 3.17.2~172 X-Git-Url: http://git.claws-mail.org/?p=claws.git;a=commitdiff_plain;h=48ba0be464519da10458f55d0587a6a67c630556 Fix wrong logics leading to writing possibly broken config file, patch by Olivier Brunel. --- diff --git a/src/common/prefs.c b/src/common/prefs.c index d621a7a22..23bcc2208 100644 --- a/src/common/prefs.c +++ b/src/common/prefs.c @@ -278,7 +278,7 @@ gint prefs_set_block_label(PrefFile *pfile, const gchar *label) { gchar *block_label; gchar buf[BUFFSIZE]; - + block_label = g_strdup_printf("[%s]", label); if (!pfile->writing) { while (fgets(buf, sizeof(buf), pfile->fp) != NULL) { @@ -296,7 +296,7 @@ gint prefs_set_block_label(PrefFile *pfile, const gchar *label) while (fgets(buf, sizeof(buf), pfile->orig_fp) != NULL) { gint val; - + val = strncmp(buf, block_label, strlen(block_label)); if (val == 0) { debug_print("Found %s\n", block_label); @@ -312,20 +312,20 @@ gint prefs_set_block_label(PrefFile *pfile, const gchar *label) } } } - + if (!block_matched) { fclose(pfile->orig_fp); pfile->orig_fp = NULL; } - - if (fputs(block_label, pfile->fp) == EOF || - fputc('\n', pfile->fp) == EOF) { - g_warning("failed to write configuration to file"); - prefs_file_close_revert(pfile); - g_free(block_label); - - return -1; - } + } + + if (fputs(block_label, pfile->fp) == EOF || + fputc('\n', pfile->fp) == EOF) { + g_warning("failed to write configuration to file"); + prefs_file_close_revert(pfile); + g_free(block_label); + + return -1; } }