From 24bff87107d89a09e724993e053e7151945596e8 Mon Sep 17 00:00:00 2001 From: Zufu Liu Date: Sat, 29 Jun 2019 11:57:11 +1000 Subject: Bug [#2115]. Fix undefined behaviour of shifting negative values. --- src/PositionCache.cxx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/PositionCache.cxx b/src/PositionCache.cxx index ea281f7ab..e9edb84e7 100644 --- a/src/PositionCache.cxx +++ b/src/PositionCache.cxx @@ -723,10 +723,11 @@ bool PositionCacheEntry::Retrieve(unsigned int styleNumber_, const char *s_, } unsigned int PositionCacheEntry::Hash(unsigned int styleNumber_, const char *s, unsigned int len_) noexcept { - unsigned int ret = s[0] << 7; + const unsigned char *us = reinterpret_cast(s); + unsigned int ret = us[0] << 7; for (unsigned int i=0; i