summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremy Huddleston Sequoia <jeremyhu@apple.com>2022-11-26 21:55:16 -0800
committerJeremy Huddleston Sequoia <jeremyhu@apple.com>2022-11-26 22:35:40 -0800
commit572d9d52f408f23905d3af22a02108991944ab2d (patch)
tree07beb57309c6c27f1da8a3946857c6e3462f5043
parent5ca90ec8665294cb8499a54c303b8275eeeaaf4d (diff)
atom: Update Hash() to be unsigned
This avoids undefined behavior (left shift overflow in signed integer type) Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com>
-rw-r--r--src/stubs/atom.c34
1 files changed, 16 insertions, 18 deletions
diff --git a/src/stubs/atom.c b/src/stubs/atom.c
index afc186c..367ddc9 100644
--- a/src/stubs/atom.c
+++ b/src/stubs/atom.c
@@ -46,37 +46,35 @@ typedef struct _AtomList {
static AtomListPtr *hashTable;
-static int hashSize, hashUsed;
-static int hashMask;
-static int rehash;
+static unsigned hashSize, hashUsed;
+static unsigned hashMask;
+static unsigned rehash;
static AtomListPtr *reverseMap;
static int reverseMapSize;
static Atom lastAtom;
-static int
-Hash(const char *string, int len)
+static unsigned
+Hash(const char *string, unsigned len)
{
- int h;
+ unsigned h = 0;
- h = 0;
while (len--)
h = (h << 3) ^ *string++;
- if (h < 0)
- return -h;
+
return h;
}
static int
ResizeHashTable(void)
{
- int newHashSize;
- int newHashMask;
+ unsigned newHashSize;
+ unsigned newHashMask;
AtomListPtr *newHashTable;
- int i;
- int h;
- int newRehash;
- int r;
+ unsigned i;
+ unsigned h;
+ unsigned newRehash;
+ unsigned r;
if (hashSize == 0)
newHashSize = 1024;
@@ -148,9 +146,9 @@ Atom
__libxfont_internal__MakeAtom(const char *string, unsigned len, int makeit)
{
AtomListPtr a;
- int hash;
- int h = 0;
- int r;
+ unsigned hash;
+ unsigned h = 0;
+ unsigned r;
hash = Hash(string, len);
if (hashTable) {