From 896698a4f5c25b391aa5eef8c72d995ce5fec4ac Mon Sep 17 00:00:00 2001 From: Stefan Weil Date: Sun, 10 Mar 2019 20:44:38 +0100 Subject: [PATCH] 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 --- src/training/util.h | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/training/util.h b/src/training/util.h index 3e9957b1e..c16565c60 100644 --- a/src/training/util.h +++ b/src/training/util.h @@ -2,7 +2,6 @@ * File: util.h * Description: Misc STL string utility functions. * Author: Samuel Charron - * Created: Mon Nov 18 2013 * * (C) Copyright 2013, Google Inc. * Licensed under the Apache License, Version 2.0 (the "License"); @@ -32,8 +31,8 @@ struct StringHash { size_t operator()(const std::string& s) const { size_t hash_code = 0; - const char* str = s.c_str(); - for (int ch = 0; str[ch] != 0; ++ch) { + const uint8_t* str = reinterpret_cast(s.c_str()); + for (unsigned ch = 0; str[ch] != 0; ++ch) { hash_code += str[ch] << (ch % 24); } return hash_code; @@ -43,8 +42,8 @@ struct StringHash { struct StringHash : public stdext::hash_compare { size_t operator()(const std::string& s) const { size_t hash_code = 0; - const char* str = s.c_str(); - for (int ch = 0; str[ch] != 0; ++ch) { + const uint8_t* str = reinterpret_cast(s.c_str()); + for (unsigned ch = 0; str[ch] != 0; ++ch) { hash_code += str[ch] << (ch % 24); } return hash_code;