From 806e8e439f3e6fe416bfb9acc972b8ba1c7d0a42 Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Sat, 10 Jul 2021 16:07:33 +0200 Subject: [PATCH] tweaks: reshuffle some lines to elide a variable Having a local variable that gets assigned to just once looks rather poor. To me it makes more sense to have two separate exit points: one for failure somewhere in the middle, and one for success at the end. This way it is completely clear which value gets returned when. --- src/files.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/files.c b/src/files.c index 202f5cf8..26d8281b 100644 --- a/src/files.c +++ b/src/files.c @@ -1758,8 +1758,6 @@ bool write_file(const char *name, FILE *thefile, bool tmp, /* An iterator for moving through the lines of the buffer. */ size_t lineswritten = 0; /* The number of lines written, for feedback on the status bar. */ - bool retval = FALSE; - /* The return value, to become TRUE when writing has succeeded. */ #ifdef ENABLE_OPERATINGDIR /* If we're writing a temporary file, we're probably going outside @@ -1955,7 +1953,11 @@ bool write_file(const char *name, FILE *thefile, bool tmp, if (fclose(thefile) != 0) { statusline(ALERT, _("Error writing %s: %s"), realname, strerror(errno)); - goto cleanup_and_exit; + + cleanup_and_exit: + free(tempname); + free(realname); + return FALSE; } /* When having written an entire buffer, update some administrivia. */ @@ -2011,13 +2013,11 @@ bool write_file(const char *name, FILE *thefile, bool tmp, if (!tmp) statusline(REMARK, P_("Wrote %zu line", "Wrote %zu lines", lineswritten), lineswritten); - retval = TRUE; - cleanup_and_exit: free(tempname); free(realname); - return retval; + return TRUE; } #ifndef NANO_TINY