diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--source/cache.c19
1 file changed, 9 insertions, 10 deletions
diff --git a/source/cache.c b/source/cache.c
index aff0f4d..105ecfe 100644
--- a/source/cache.c
+++ b/source/cache.c
@@ -21,6 +21,12 @@
#endif
#define CACHE_BUFSIZE (1024 * 4)
+/* Crude implementation of 32-bit FNV-1 hash algorithm,
+ * see http://www.isthe.com/chongo/tech/comp/fnv/ for details
+ * about the magic numbers.
+ */
+#define FNV_OFFSET 0x811c9dc5
+#define FNV_PRIME 0x01000193
struct cache_slot {
const char *key;
@@ -63,7 +69,7 @@ static int open_slot(struct cache_slot *slot)
bufkeylen = bufz - slot->buf;
if (slot->key)
- slot->match = bufkeylen == slot->keylen &&
+ slot->match = bufkeylen >= 0 && (size_t)bufkeylen == slot->keylen &&
!memcmp(slot->key, slot->buf, bufkeylen + 1);
return 0;
@@ -246,14 +252,7 @@ static int fill_slot(struct cache_slot *slot)
return 0;
}
-/* Crude implementation of 32-bit FNV-1 hash algorithm,
- * see http://www.isthe.com/chongo/tech/comp/fnv/ for details
- * about the magic numbers.
- */
-#define FNV_OFFSET 0x811c9dc5
-#define FNV_PRIME 0x01000193
-
-unsigned long hash_str(const char *str)
+unsigned long cache_hash_str(const char *str)
{
unsigned long h = FNV_OFFSET;
unsigned char *s = (unsigned char *)str;
@@ -379,7 +378,7 @@ int cache_process(int size, const char *path, const char *key, int ttl,
}
if (!key)
key = "";
- hash = hash_str(key) % size;
+ hash = cache_hash_str(key) % size;
strbuf_addstr(&filename, path);
strbuf_ensure_end(&filename, '/');
for (i = 0; i < 8; i++) {