From 8055d6b002a425841cac4cd6ea97b4a2b0691404 Mon Sep 17 00:00:00 2001 From: divverent Date: Tue, 18 Dec 2007 21:08:08 +0000 Subject: [PATCH] add a CRC_Block_CaseInsensitive that tolowers its input for use by hash functions for case insensitive hash tables; make the shader system use it (fixes accidentally introduced case sensitivity by res2k) git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@7821 d7cf8633-e32d-0410-b094-e92efae38249 --- common.c | 8 ++++++++ common.h | 1 + model_shared.c | 4 ++-- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/common.c b/common.c index aaa9fd68..b648b017 100644 --- a/common.c +++ b/common.c @@ -173,6 +173,14 @@ unsigned short CRC_Block(const unsigned char *data, size_t size) return crc ^ CRC_XOR_VALUE; } +unsigned short CRC_Block_CaseInsensitive(const unsigned char *data, size_t size) +{ + unsigned short crc = CRC_INIT_VALUE; + while (size--) + crc = (crc << 8) ^ crctable[(crc >> 8) ^ (tolower(*data++))]; + return crc ^ CRC_XOR_VALUE; +} + // QuakeWorld static unsigned char chktbl[1024 + 4] = { diff --git a/common.h b/common.h index 3111ee22..52466fd6 100644 --- a/common.h +++ b/common.h @@ -60,6 +60,7 @@ void SZ_HexDumpToConsole(const sizebuf_t *buf); void Com_HexDumpToConsole(const unsigned char *data, int size); unsigned short CRC_Block(const unsigned char *data, size_t size); +unsigned short CRC_Block_CaseInsensitive(const unsigned char *data, size_t size); // for hash lookup functions that use strcasecmp for comparison unsigned char COM_BlockSequenceCRCByteQW(unsigned char *base, int length, int sequence); diff --git a/model_shared.c b/model_shared.c index 5825d1fa..4f046300 100644 --- a/model_shared.c +++ b/model_shared.c @@ -1145,7 +1145,7 @@ static void Q3Shaders_Clear() static void Q3Shader_AddToHash (q3shaderinfo_t* shader) { - unsigned short hash = CRC_Block ((const unsigned char *)shader->name, strlen (shader->name)); + unsigned short hash = CRC_Block_CaseInsensitive ((const unsigned char *)shader->name, strlen (shader->name)); q3shader_hash_entry_t* entry = q3shader_data->hash + (hash % Q3SHADER_HASH_SIZE); q3shader_hash_entry_t* lastEntry = NULL; while (entry != NULL) @@ -1666,7 +1666,7 @@ void Mod_LoadQ3Shaders(void) q3shaderinfo_t *Mod_LookupQ3Shader(const char *name) { - unsigned short hash = CRC_Block ((const unsigned char *)name, strlen (name)); + unsigned short hash = CRC_Block_CaseInsensitive ((const unsigned char *)name, strlen (name)); q3shader_hash_entry_t* entry = q3shader_data->hash + (hash % Q3SHADER_HASH_SIZE); while (entry != NULL) { -- 2.39.2