From c705a815a808e7eafd2043fe0ec0881d602342c5 Mon Sep 17 00:00:00 2001 From: Nickolai Zeldovich Date: Wed, 27 Feb 2013 05:08:40 -0500 Subject: [PATCH] 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 --- src/ptserver/testpt.c | 2 -- 1 file changed, 2 deletions(-) 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); -- 2.39.5