]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
lib/copydir.c: Use goto to reduce a conditional branch
authorAlejandro Colomar <alx@kernel.org>
Wed, 4 Oct 2023 16:46:48 +0000 (18:46 +0200)
committerAlejandro Colomar <alx@kernel.org>
Fri, 20 Oct 2023 19:05:33 +0000 (21:05 +0200)
Reviewed-by: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
lib/copydir.c

index 4c1b78bea6ffc7bed7ad0e55bed4b8ca4d3df6e2..36f2004d14fe87ac5760b1b541671780262fc60b 100644 (file)
@@ -335,27 +335,28 @@ static int copy_tree_impl (const struct path_info *src, const struct path_info *
 
                if ((NULL == src_name) || (NULL == dst_name)) {
                        err = -1;
-               } else {
-                       /*
-                        * Build the filename for both the source and
-                        * the destination files.
-                        */
-                       struct path_info src_entry, dst_entry;
+                       goto skip;
+               }
+               /*
+                * Build the filename for both the source and
+                * the destination files.
+                */
+               struct path_info src_entry, dst_entry;
 
-                       (void) snprintf (src_name, src_len, "%s/%s", src->full_path, ent->d_name);
-                       (void) snprintf (dst_name, dst_len, "%s/%s", dst->full_path, ent->d_name);
+               (void) snprintf (src_name, src_len, "%s/%s", src->full_path, ent->d_name);
+               (void) snprintf (dst_name, dst_len, "%s/%s", dst->full_path, ent->d_name);
 
-                       src_entry.full_path = src_name;
-                       src_entry.dirfd = dirfd(dir);
-                       src_entry.name = ent->d_name;
+               src_entry.full_path = src_name;
+               src_entry.dirfd = dirfd(dir);
+               src_entry.name = ent->d_name;
 
-                       dst_entry.full_path = dst_name;
-                       dst_entry.dirfd = dst_fd;
-                       dst_entry.name = ent->d_name;
+               dst_entry.full_path = dst_name;
+               dst_entry.dirfd = dst_fd;
+               dst_entry.name = ent->d_name;
 
-                       err = copy_entry(&src_entry, &dst_entry, reset_selinux,
-                                        old_uid, new_uid, old_gid, new_gid);
-               }
+               err = copy_entry(&src_entry, &dst_entry, reset_selinux,
+                                old_uid, new_uid, old_gid, new_gid);
+skip:
                free (src_name);
                free (dst_name);
        }