summaryrefslogtreecommitdiff
path: root/src/cp-hash.c
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>1997-11-30 10:24:54 +0000
committerJim Meyering <jim@meyering.net>1997-11-30 10:24:54 +0000
commita5fe3a240b7bf15077b30bba1a205a8af27c5d2b (patch)
tree3913198c41a5621a6f85061c600c31b58a8b5d3a /src/cp-hash.c
parentb8c474191af9b458b0b9a82eaa1e28a44730f544 (diff)
downloadcoreutils-a5fe3a240b7bf15077b30bba1a205a8af27c5d2b.tar.xz
(<inttypes.h>): Include if HAVE_INTTYPES_H.
(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.
Diffstat (limited to 'src/cp-hash.c')
-rw-r--r--src/cp-hash.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/cp-hash.c b/src/cp-hash.c
index e9535d453..ee6d0f21e 100644
--- a/src/cp-hash.c
+++ b/src/cp-hash.c
@@ -18,6 +18,10 @@
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? */