fix mem access problem reported by sanitizer

This commit is contained in:
yancey 2023-07-22 14:00:03 -04:00
parent d12e540830
commit e66eddd1d5
2 changed files with 5 additions and 5 deletions

View File

@ -1,5 +1,5 @@
#note: experimental #note: experimental
# currently only used for generating `compile_commands.json` for clangd # currently only used for generating `compile_commands.json` for clangd.
# to build this project, it's suggested to use `makefile` instead # to build this project, it's suggested to use `makefile` instead
cmake_minimum_required(VERSION 3.7) cmake_minimum_required(VERSION 3.7)

View File

@ -1127,8 +1127,8 @@ void print_binary_chars(const char *a, int len) {
u32_t djb2(unsigned char *str, int len) { u32_t djb2(unsigned char *str, int len) {
u32_t hash = 5381; u32_t hash = 5381;
int c; int c;
int i = 0; for (int i=0; i<len ;i++) {
while (c = *str++, i++ != len) { c = *(str++);
hash = ((hash << 5) + hash) ^ c; /* (hash * 33) ^ c */ hash = ((hash << 5) + hash) ^ c; /* (hash * 33) ^ c */
} }
@ -1139,8 +1139,8 @@ u32_t djb2(unsigned char *str, int len) {
u32_t sdbm(unsigned char *str, int len) { u32_t sdbm(unsigned char *str, int len) {
u32_t hash = 0; u32_t hash = 0;
int c; int c;
int i = 0; for (int i=0; i<len ;i++) {
while (c = *str++, i++ != len) { c = *(str++);
hash = c + (hash << 6) + (hash << 16) - hash; hash = c + (hash << 6) + (hash << 16) - hash;
} }
// hash=htonl(hash); // hash=htonl(hash);