Skip to content

Commit 896698a

Browse files
committed
Fix runtime error (left shift of negative value)
Runtime error: src/training/util.h:37:28: runtime error: left shift of negative value -17 Signed-off-by: Stefan Weil <[email protected]>
1 parent 59cd716 commit 896698a

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

src/training/util.h

+4-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
* File: util.h
33
* Description: Misc STL string utility functions.
44
* Author: Samuel Charron
5-
* Created: Mon Nov 18 2013
65
*
76
* (C) Copyright 2013, Google Inc.
87
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -32,8 +31,8 @@
3231
struct StringHash {
3332
size_t operator()(const std::string& s) const {
3433
size_t hash_code = 0;
35-
const char* str = s.c_str();
36-
for (int ch = 0; str[ch] != 0; ++ch) {
34+
const uint8_t* str = reinterpret_cast<const uint8_t*>(s.c_str());
35+
for (unsigned ch = 0; str[ch] != 0; ++ch) {
3736
hash_code += str[ch] << (ch % 24);
3837
}
3938
return hash_code;
@@ -43,8 +42,8 @@ struct StringHash {
4342
struct StringHash : public stdext::hash_compare <std::string> {
4443
size_t operator()(const std::string& s) const {
4544
size_t hash_code = 0;
46-
const char* str = s.c_str();
47-
for (int ch = 0; str[ch] != 0; ++ch) {
45+
const uint8_t* str = reinterpret_cast<const uint8_t*>(s.c_str());
46+
for (unsigned ch = 0; str[ch] != 0; ++ch) {
4847
hash_code += str[ch] << (ch % 24);
4948
}
5049
return hash_code;

0 commit comments

Comments
 (0)