diff options
author | Nicolas François <nicolas.francois@centraliens.net> | 2013-08-13 23:55:48 +0200 |
---|---|---|
committer | Nicolas François <nicolas.francois@centraliens.net> | 2013-08-14 00:19:19 +0200 |
commit | b84b918464c4ea66be3dec1c54e418d40ce5cebb (patch) | |
tree | 2ea602b2d745642b8b5ab89367c5d456c682c67c | |
parent | 00f573fce2fd4a0262e64457961252528642cf4c (diff) |
Avoid dead branches.
* lib/subordinateio.c: Avoid dead branches.
Note: code is equivalent.
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | lib/subordinateio.c | 70 |
2 files changed, 41 insertions, 33 deletions
@@ -1,5 +1,9 @@ 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. Debian#677812 diff --git a/lib/subordinateio.c b/lib/subordinateio.c index 6ed95028..25a2d304 100644 --- a/lib/subordinateio.c +++ b/lib/subordinateio.c @@ -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; + } } } |