]> git.michaelhowe.org Git - packages/o/openafs.git/commitdiff
Fix incorrect uses of abs()
authorBen Kaduk <kaduk@mit.edu>
Fri, 13 Feb 2015 14:47:20 +0000 (09:47 -0500)
committerStephan Wiesand <stephan.wiesand@desy.de>
Thu, 28 May 2015 12:48:02 +0000 (08:48 -0400)
abs(3) is a function of one variable of type int returning int.
labs(3) is a function of one variable of type long returning long.

labs(3) should be used when the input is of type long, as in
kaprocs.c.

Calling anything from the abs(3) family on a variable of unsigned
type is a bogus type pun, and a logical operation which is a no-op.
(Unsigned values are never negative and thus the absolute value
function is the identity over the entire range of values representable
in an unsigned type.)  Just remove the use of abs() for unsigned
values, as in kaprocs.c, krb_udp.c, and vldb_check.c

While in kaprocs.c, wrap a long line that was touched for the
conversion to labs(3), spell the argument to time(3) as NULL
instead of 0, remove unneeded parentheses, and correct the spelling
of "reserved".

Reviewed-on: http://gerrit.openafs.org/11745
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Chas Williams - CONTRACTOR <chas@cmf.nrl.navy.mil>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
(cherry picked from commit 5b3c1042969daec38ccb260e61d665eda0c713ea)

Change-Id: I82038e41346479dad39466907b95f2d7540f6258
Reviewed-on: http://gerrit.openafs.org/11842
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
Reviewed-by: Stephan Wiesand <stephan.wiesand@desy.de>
src/kauth/kaprocs.c
src/kauth/krb_udp.c
src/vlserver/vldb_check.c

index 7298b862c09689d8354ce8254142cda10e97ca75..e055c71a25a6db4532704fc184e978ea7aa0a432 100644 (file)
@@ -711,7 +711,9 @@ ChangePassWord(struct rx_call *call, char *aname, char *ainstance,
     /* validate the request */
     request_time = ntohl(request.time);        /* reorder date */
     kvno = ntohl(request.kvno);
-    if ((abs(request_time - time(0)) > KTC_TIME_UNCERTAINTY) || strncmp(request.label, KA_CPW_REQ_LABEL, sizeof(request.label)) || (request.spare) || (kvno > MAXKAKVNO)) {    /* these are reseved */
+    if (labs(request_time - time(NULL)) > KTC_TIME_UNCERTAINTY ||
+       strncmp(request.label, KA_CPW_REQ_LABEL, sizeof(request.label)) ||
+       request.spare || kvno > MAXKAKVNO) {    /* these are reserved */
        code = KABADREQUEST;
        goto abort;
     }
@@ -1140,7 +1142,7 @@ Authenticate(int version, struct rx_call *call, char *aname, char *ainstance,
     }
 #endif /* EXPIREPW */
 
-    if (abs(request.time - now) > KTC_TIME_UNCERTAINTY) {
+    if (request.time - now > KTC_TIME_UNCERTAINTY) {
 #if 0
        if (oanswer->MaxSeqLen < sizeof(afs_int32))
            code = KAANSWERTOOLONG;
index b1f8ffad7dee6472aee455766cdc4790a8b8e29c..c988370505730db7accfa6c1565f80623faa33e3 100644 (file)
@@ -297,7 +297,7 @@ UDP_Authenticate(int ksoc, struct sockaddr_in *client, char *name,
            code = KERB_ERR_NAME_EXP;   /* XXX Could use another error code XXX */
            goto abort;
        }
-       if (abs(startTime - now) > KTC_TIME_UNCERTAINTY) {
+       if (startTime - now > KTC_TIME_UNCERTAINTY) {
            code = KERB_ERR_SERVICE_EXP;        /* was KABADREQUEST */
            goto abort;
        }
index 903b81b883e7e736aa600063520100d9732b31e0..59f75d8ecf6a86c5de84b52deb76597c1cfb6ff8 100644 (file)
@@ -223,7 +223,7 @@ NameHash(char *volname)
 afs_int32
 IdHash(afs_uint32 volid)
 {
-    return ((abs(volid)) % HASHSIZE);
+    return (volid % HASHSIZE);
 }
 
 #define LEGALCHARS ".ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"