about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2018-08-14 14:04:20 -0400
committerJune McEnroe <june@causal.agency>2018-08-14 14:04:20 -0400
commit398f752322f5199c6f25bde57e2befd1b570862b (patch)
tree2ae4eb950abadeba8536d9fabe59d6d0e4fc6ba1
parentSet title to tag name (diff)
downloadcatgirl-398f752322f5199c6f25bde57e2befd1b570862b.tar.gz
catgirl-398f752322f5199c6f25bde57e2befd1b570862b.zip
Keep hashing '\0' until color is not black
Actually uses the rest of the hash state this way.
-rw-r--r--handle.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/handle.c b/handle.c
index 16a416c..c93522e 100644
--- a/handle.c
+++ b/handle.c
@@ -25,16 +25,22 @@
 #include "chat.h"
 
 // Adapted from <https://github.com/cbreeden/fxhash/blob/master/lib.rs>.
+static uint32_t hashChar(uint32_t hash, char ch) {
+	hash = (hash << 5) | (hash >> 27);
+	hash ^= ch;
+	hash *= 0x27220A95;
+	return hash;
+}
 static int color(const char *str) {
 	if (!str) return IRC_GRAY;
 	uint32_t hash = 0;
 	for (; str[0]; ++str) {
-		hash = (hash << 5) | (hash >> 27);
-		hash ^= str[0];
-		hash *= 0x27220A95;
+		hash = hashChar(hash, str[0]);
+	}
+	while (IRC_BLACK == (hash & IRC_LIGHT_GRAY)) {
+		hash = hashChar(hash, '\0');
 	}
-	hash &= IRC_LIGHT_GRAY;
-	return (hash == IRC_BLACK) ? IRC_GRAY : hash;
+	return (hash & IRC_LIGHT_GRAY);
 }
 
 static char *paramField(char **params) {
2009-06-07Return http statuscode 404 on unknown branchLars Hjemli Signed-off-by: Lars Hjemli <hjemli@gmail.com> 2009-06-07Add head-include configuration option.Mark Lodato This patch adds an option to the configuration file, "head-include", which works just like "header" or "footer", except the content is put into the HTML's <head> tag. 2009-03-15CGIT 0.8.2.1Lars Hjemli Signed-off-by: Lars Hjemli <hjemli@gmail.com> 2009-03-15Fix doc-related glitches in Makefile and .gitignoreLars Hjemli Signed-off-by: Lars Hjemli <hjemli@gmail.com> 2009-03-15ui-snapshot: avoid segfault when no filename is specifiedLars Hjemli Signed-off-by: Lars Hjemli <hjemli@gmail.com> 2009-03-15fix segfault when displaying empty blobsEric Wong When size is zero, subtracting one from it turns it into ULONG_MAX which causes an out-of-bounds access on buf. Signed-off-by: Eric Wong <normalperson@yhbt.net> Signed-off-by: Lars Hjemli <hjemli@gmail.com> 2009-02-19Add support for HEAD requestsLars Hjemli This is a quick 'n dirty hack which makes cgit honor HEAD requests. Signed-off-by: Lars Hjemli <hjemli@gmail.com> 2009-02-19Add support for ETag in 'plain' viewLars Hjemli When downloading a blob identified by its path, the client might want to know if the blob has been modified since a previous download of the same path. To this end, an ETag containing the blob SHA1 seems to be ideal. Todo: add support for HEAD requests... Suggested-by: Owen Taylor <otaylor@redhat.com> Signed-off-by: Lars Hjemli <hjemli@gmail.com> 2009-02-12ui-tree: escape ascii-text properly in hexdump viewLars Hjemli Signed-off-by: Lars Hjemli <hjemli@gmail.com> 2009-02-12Makefile: add doc-related targetsLars Hjemli