[PATCH 2/3] gai_init: Avoid jumping from if condition to its else counterpart
DJ Delorie
dj@redhat.com
Thu Mar 17 23:48:00 GMT 2022
Siddhesh Poyarekar via Libc-alpha <libc-alpha@sourceware.org> writes:
> Clean up another antipattern where code flows from an if condition to
> its else counterpart with a goto.
>
> Most of the change in this patch is whitespace-only; a `git diff -b`
> ought to show the actual logic changes.
Re-diffed as "diff -EZdbwpU5" and reviewing that...
LGTM
Reviewed-by: DJ Delorie <dj@redhat.com>
> --- before.txt 2022-03-17 19:42:35.903049857 -0400
> +++ after.txt 2022-03-17 19:42:49.976581858 -0400
> @@ -1834,12 +1834,13 @@ gaiconf_init (void)
> struct scopelist *scopelist = NULL;
> size_t nscopelist = 0;
> bool scopelist_nullbits = false;
>
> FILE *fp = fopen (GAICONF_FNAME, "rce");
> + if (fp == NULL)
> + goto no_file;
> +
> - if (fp != NULL)
> - {
Ok.
> struct __stat64_t64 st;
> if (__fstat64_time64 (fileno (fp), &st) != 0)
> {
> fclose (fp);
> goto no_file;
> @@ -2131,24 +2132,21 @@ gaiconf_init (void)
> scopes = new_scopes;
> if (oldscope != default_scopes)
> free ((void *) oldscope);
>
> save_gaiconf_mtime (&st);
> - }
> - else
> - {
> + return;
> +
Ok.
> no_file:
> free_prefixlist (labellist);
> free_prefixlist (precedencelist);
> free_scopelist (scopelist);
>
> - /* If we previously read the file but it is gone now, free the
> - old data and use the builtin one. Leave the reload flag
> - alone. */
> + /* If we previously read the file but it is gone now, free the old data and
> + use the builtin one. Leave the reload flag alone. */
> fini ();
> }
> -}
Ok.
More information about the Libc-alpha
mailing list