From: Nickolai Zeldovich Date: Wed, 27 Feb 2013 10:08:40 +0000 (-0500) Subject: ptserver/testpt.c: remove dead code in ListUsedIds X-Git-Tag: upstream/1.8.0_pre1^2~1405 X-Git-Url: https://git.michaelhowe.org/gitweb/?a=commitdiff_plain;h=c705a815a808e7eafd2043fe0ec0881d602342c5;p=packages%2Fo%2Fopenafs.git ptserver/testpt.c: remove dead code in ListUsedIds 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 Reviewed-by: Simon Wilkinson Reviewed-by: Derrick Brashear --- diff --git a/src/ptserver/testpt.c b/src/ptserver/testpt.c index 766b8c57a..8ddf42976 100644 --- a/src/ptserver/testpt.c +++ b/src/ptserver/testpt.c @@ -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);