Avoid dead branches.

* lib/subordinateio.c: Avoid dead branches.

Note: code is equivalent.
This commit is contained in:
Nicolas François 2013-08-13 23:55:48 +02:00
parent 00f573fce2
commit b84b918464
2 changed files with 36 additions and 28 deletions

View File

@ -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> 2013-08-13 Nicolas François <nicolas.francois@centraliens.net>
* src/vipw.c: Fail in case arguments are provided after options. * src/vipw.c: Fail in case arguments are provided after options.

View File

@ -309,39 +309,43 @@ static int remove_range(struct commonio_db *db,
if ((end < first) || (start > last)) if ((end < first) || (start > last))
continue; continue;
/* Is entry completely contained in the range to remove? */ if (start <= first) {
if ((start <= first) && (end >= last)) { if (end >= last) {
commonio_del_entry (db, ent); /* entry completely contained in the
} * range to remove */
/* Is just the start of the entry removed? */ commonio_del_entry (db, ent);
else if ((start <= first) && (end < last)) { } else {
range->start = end + 1; /* Remove only the start of the entry */
range->count = (last - range->start) + 1; range->start = end + 1;
range->count = (last - range->start) + 1;
ent->changed = true; ent->changed = true;
db->changed = true; db->changed = true;
} }
/* Is just the end of the entry removed? */ } else {
else if ((start > first) && (end >= last)) { if (end >= last) {
range->count = start - range->start; /* Remove only the end of the entry */
range->count = start - range->start;
ent->changed = true; ent->changed = true;
db->changed = true; db->changed = true;
} } else {
/* The middle of the range is removed */ /* Remove the middle of the range
else { * This requires to create a new range */
struct subordinate_range tail; struct subordinate_range tail;
tail.owner = range->owner; tail.owner = range->owner;
tail.start = end + 1; tail.start = end + 1;
tail.count = (last - tail.start) + 1; tail.count = (last - tail.start) + 1;
if (!commonio_append(db, &tail)) if (commonio_append(db, &tail) == 0) {
return 0; return 0;
}
range->count = start - range->start; range->count = start - range->start;
ent->changed = true; ent->changed = true;
db->changed = true; db->changed = true;
}
} }
} }