Hacker News new | ask | show | jobs
by userbinator 1164 days ago
I suspect the author of the hash function thought this wouldn't add more than 4 bits:

    h = (h << 4) + *name++;
But as one should know, two n-bit numbers can create an n+1-bit result when added due to carry.
2 comments

I think the issue is that, when written, a `long` was 32 bits. I would guess the author was familiar with the concept of a carry bit, but they didn't care because the carry bit was discarded by their architecture.
I added this sentence to the article, hopefully making it clearer:

> If h is in the range [0x0fffff01,0x0fffffff] in the previous iteration, shifting it by 4 and adding *name may make h larger than UINT32_MAX.