ptserver/testpt.c: remove dead code in ListUsedIds
authorNickolai Zeldovich <nickolai@csail.mit.edu>
Wed, 27 Feb 2013 10:08:40 +0000 (05:08 -0500)
committerDerrick Brashear <shadow@your-file-system.com>
Wed, 27 Feb 2013 14:55:13 +0000 (06:55 -0800)
A part of the current ListUsedIds code is:

    range = abs(startId - maxId);
    if (range < 0)
       range = -range;

The only way abs() could return a negative value would be if its
argument was INT_MIN (-2147483648) to begin with, because -INT_MIN
cannot be represented in two's complement.  However, calling
abs(INT_MIN) is undefined behavior in C [see C99 7.20.6.1], and for
that matter, so would be computing -range (-INT_MIN) in that case,
so we could still be left with a negative range value.

Luckily, (startId - maxId) can never be INT_MIN.  If startId < 0,
then maxId <= startId, so in the worst case, when maxId = INT_MIN
and startId = -1, (startId-maxId)=INT_MAX.  If startId >= 0, then
maxId >= startId, so in the worst case, when maxId = INT_MAX and
startId = 0, (startId-maxId)=-INT_MAX=INT_MIN+1.

This patch removes the useless if statement.

Change-Id: Ia754fcf3e59354afb40dbbbb95623e27285a5f82
Reviewed-on: http://gerrit.openafs.org/9289
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Simon Wilkinson <simonxwilkinson@gmail.com>
Reviewed-by: Derrick Brashear <shadow@your-file-system.com>

src/ptserver/testpt.c

index 766b8c5..8ddf429 100644 (file)
@@ -87,8 +87,6 @@ ListUsedIds(struct cmd_syndesc *as, void *arock)
        }
     }
     range = abs(startId - maxId);
-    if (range < 0)
-       range = -range;
     range++;                   /* number that can be printed */
     if (range < number) {
        fprintf(stderr, "Only %d ids to be checked.\n", range);