]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
(<inttypes.h>): Include if HAVE_INTTYPES_H.
authorJim Meyering <jim@meyering.net>
Sun, 30 Nov 1997 10:24:54 +0000 (10:24 +0000)
committerJim Meyering <jim@meyering.net>
Sun, 30 Nov 1997 10:24:54 +0000 (10:24 +0000)
(hash_insert2): Cast inode number to uintmax_t; this prevents
negative remainders if the inode number is negative and ino_t
is longer than unsigned.

src/cp-hash.c

index e9535d4538b5255ab02dccf061c16c14608eccc8..ee6d0f21ed5d4751c0b17cee9d847addc4f589bc 100644 (file)
    Written by Torbjorn Granlund, Sweden (tege@sics.se). */
 
 #include <config.h>
+
+#if HAVE_INTTYPES_H
+# include <inttypes.h>
+#endif
 #include <stdio.h>
 #include <sys/types.h>
 #include "system.h"
@@ -121,7 +125,10 @@ static char *
 hash_insert2 (struct htab *ht, ino_t ino, dev_t dev, const char *node)
 {
   struct entry **hp, *ep2, *ep;
-  hp = &ht->hash[ino % ht->modulus];
+
+  /* The cast to uintmax_t prevents negative remainders if ino is negative.  */
+  hp = &ht->hash[(uintmax_t) ino % ht->modulus];
+
   ep2 = *hp;
 
   /* Collision?  */