Fixed a divide by zero error in the hash functions

This commit is contained in:
skidau 2012-02-25 20:36:49 +11:00
parent b251880d8b
commit b8bef29bcc

View File

@ -167,7 +167,13 @@ u64 GetMurmurHash3(const u8 *src, int len, u32 samples)
const u8 * data = (const u8*)src;
const int nblocks = len / 16;
u32 Step = (len / 8);
if(samples == 0) samples = Step;
if(samples == 0)
{
if (Step == 0)
samples = 1;
else
samples = Step;
}
Step = Step / samples;
if(Step < 1) Step = 1;
@ -245,7 +251,13 @@ u64 GetCRC32(const u8 *src, int len, u32 samples)
u32 Step = (len / 8);
const u64 *data = (const u64 *)src;
const u64 *end = data + Step;
if(samples == 0) samples = Step;
if(samples == 0)
{
if (Step == 0)
samples = 1;
else
samples = Step;
}
Step = Step / samples;
if(Step < 1) Step = 1;
while(data < end)
@ -275,7 +287,13 @@ u64 GetHashHiresTexture(const u8 *src, int len, u32 samples)
u32 Step = (len / 8);
const u64 *data = (const u64 *)src;
const u64 *end = data + Step;
if(samples == 0) samples = Step;
if(samples == 0)
{
if (Step == 0)
samples = 1;
else
samples = Step;
}
Step = Step / samples;
if(Step < 1) Step = 1;
while(data < end)
@ -318,7 +336,13 @@ u64 GetCRC32(const u8 *src, int len, u32 samples)
u32 Step = (len/4);
const u32 *data = (const u32 *)src;
const u32 *end = data + Step;
if(samples == 0) samples = Step;
if(samples == 0)
{
if (Step == 0)
samples = 1;
else
samples = Step;
}
Step = Step / samples;
if(Step < 1) Step = 1;
while(data < end)
@ -390,7 +414,13 @@ u64 GetMurmurHash3(const u8* src, int len, u32 samples)
u32 out[2];
const int nblocks = len / 8;
u32 Step = (len / 4);
if(samples == 0) samples = Step;
if(samples == 0)
{
if (Step == 0)
samples = 1;
else
samples = Step;
}
Step = Step / samples;
if(Step < 1) Step = 1;
@ -464,7 +494,13 @@ u64 GetHashHiresTexture(const u8 *src, int len, u32 samples)
u32 Step = (len / 8);
const u64 *data = (const u64 *)src;
const u64 *end = data + Step;
if(samples == 0) samples = Step;
if(samples == 0)
{
if (Step == 0)
samples = 1;
else
samples = Step;
}
Step = Step / samples;
if(Step < 1) Step = 1;
while(data < end)