mirror of
https://github.com/sigmasternchen/macrofuck
synced 2025-03-15 07:08:56 +00:00
fix: int overflow in hash_string() function results in negative bucket id
This commit is contained in:
parent
650e47f693
commit
cdc7eab841
2 changed files with 6 additions and 3 deletions
|
@ -7,8 +7,8 @@
|
|||
#include "alloc.h"
|
||||
#include "list.h"
|
||||
|
||||
int hash_string(const char* str) {
|
||||
int result = 0;
|
||||
unsigned int hash_string(const char* str) {
|
||||
unsigned int result = 0;
|
||||
while (*str != '\0') {
|
||||
result = *str + 31 * result;
|
||||
str++;
|
||||
|
@ -38,7 +38,7 @@ struct dict_pair* dict_search_in_bucket(dict_bucket_t bucket, const char* key) {
|
|||
}
|
||||
|
||||
dict_bucket_t dict_find_bucket(dict_t* dict, const char* key) {
|
||||
int hash = hash_string(key);
|
||||
unsigned int hash = hash_string(key);
|
||||
return dict->buckets[hash % NUMBER_OF_BUCKETS];
|
||||
}
|
||||
|
||||
|
|
3
compiler/test/cases/022-bug-negative-hashkey.in
Normal file
3
compiler/test/cases/022-bug-negative-hashkey.in
Normal file
|
@ -0,0 +1,3 @@
|
|||
var program = "foo\n";
|
||||
|
||||
print(program);
|
Loading…
Reference in a new issue