vfs: check userland buffers before reading them.
[haiku.git] / src / system / kernel / util / StringHash.cpp
blobed8bd258bc0d7ddfb29b98f83f1c9a0ca7c8ce6c
1 /*
2 * Copyright 2002-2013, Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
5 * Copyright 2001, Travis Geiselbrecht. All rights reserved.
6 * Distributed under the terms of the NewOS License.
7 */
10 #include <util/StringHash.h>
13 uint32
14 hash_hash_string(const char* string)
16 uint32 hash = 0;
17 char c;
19 // we assume hash to be at least 32 bits
20 while ((c = *string++) != 0) {
21 hash ^= hash >> 28;
22 hash <<= 4;
23 hash ^= c;
26 return hash;
30 uint32
31 hash_hash_string_part(const char* string, size_t maxLength)
33 uint32 hash = 0;
34 char c;
36 // we assume hash to be at least 32 bits
37 while (maxLength-- > 0 && (c = *string++) != 0) {
38 hash ^= hash >> 28;
39 hash <<= 4;
40 hash ^= c;
43 return hash;