]> granicus.if.org Git - shadow/commitdiff
Avoid dead branches.
authorNicolas François <nicolas.francois@centraliens.net>
Tue, 13 Aug 2013 21:55:48 +0000 (23:55 +0200)
committerNicolas François <nicolas.francois@centraliens.net>
Tue, 13 Aug 2013 22:19:19 +0000 (00:19 +0200)
* lib/subordinateio.c: Avoid dead branches.

Note: code is equivalent.

ChangeLog
lib/subordinateio.c

index 8a80e409119194526d589298066c28cf8eff7fc8..ed54e1217b02c0f271fd56aafe9c48ceb917e657 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2013-08-13  Nicolas François  <nicolas.francois@centraliens.net>
+
+       * lib/subordinateio.c: Avoid dead branches.
+
 2013-08-13  Nicolas François  <nicolas.francois@centraliens.net>
 
        * src/vipw.c: Fail in case arguments are provided after options.
index 6ed95028ce785da8d91ab50b6bd01276eb788c52..25a2d3044480a4401acdad2867266e7ea3987e1c 100644 (file)
@@ -309,39 +309,43 @@ static int remove_range(struct commonio_db *db,
                if ((end < first) || (start > last))
                        continue;
 
-               /* Is entry completely contained in the range to remove? */
-               if ((start <= first) && (end >= last)) {
-                       commonio_del_entry (db, ent);
-               } 
-               /* Is just the start of the entry removed? */
-               else if ((start <= first) && (end < last)) {
-                       range->start = end + 1;
-                       range->count = (last - range->start) + 1;
-
-                       ent->changed = true;
-                       db->changed = true;
-               }
-               /* Is just the end of the entry removed? */
-               else if ((start > first) && (end >= last)) {
-                       range->count = start - range->start;
-
-                       ent->changed = true;
-                       db->changed = true;
-               }
-               /* The middle of the range is removed */
-               else {
-                       struct subordinate_range tail;
-                       tail.owner = range->owner;
-                       tail.start = end + 1;
-                       tail.count = (last - tail.start) + 1;
-
-                       if (!commonio_append(db, &tail))
-                               return 0;
-
-                       range->count = start - range->start;
-
-                       ent->changed = true;
-                       db->changed = true;
+               if (start <= first) {
+                       if (end >= last) {
+                               /* entry completely contained in the
+                                * range to remove */
+                               commonio_del_entry (db, ent);
+                       } else {
+                               /* Remove only the start of the entry */
+                               range->start = end + 1;
+                               range->count = (last - range->start) + 1;
+
+                               ent->changed = true;
+                               db->changed = true;
+                       }
+               } else {
+                       if (end >= last) {
+                               /* Remove only the end of the entry */
+                               range->count = start - range->start;
+
+                               ent->changed = true;
+                               db->changed = true;
+                       } else {
+                               /* Remove the middle of the range
+                                * This requires to create a new range */
+                               struct subordinate_range tail;
+                               tail.owner = range->owner;
+                               tail.start = end + 1;
+                               tail.count = (last - tail.start) + 1;
+
+                               if (commonio_append(db, &tail) == 0) {
+                                       return 0;
+                               }
+
+                               range->count = start - range->start;
+
+                               ent->changed = true;
+                               db->changed = true;
+                       }
                }
        }