From 30f26a2b9d69c0629b339cc215891268b801f089 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Wed, 6 Jul 2016 23:58:53 +0900 Subject: [PATCH] nghttpx: Explicitly cast to uint32_t for hash calculation --- src/shrpx_client_handler.cc | 4 +++- src/shrpx_config.cc | 6 ++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/shrpx_client_handler.cc b/src/shrpx_client_handler.cc index 1e05e350..2c9b2a10 100644 --- a/src/shrpx_client_handler.cc +++ b/src/shrpx_client_handler.cc @@ -687,7 +687,9 @@ uint32_t compute_affinity_from_ip(const StringRef &ip) { return util::hash32(ip); } - return (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3]; + return (static_cast(buf[0]) << 24) | + (static_cast(buf[1]) << 16) | + (static_cast(buf[2]) << 8) | static_cast(buf[3]); } } // namespace diff --git a/src/shrpx_config.cc b/src/shrpx_config.cc index 3d27e6f2..f356a3fb 100644 --- a/src/shrpx_config.cc +++ b/src/shrpx_config.cc @@ -2854,8 +2854,10 @@ int compute_affinity_hash(std::vector &res, size_t idx, } for (int i = 0; i < 8; ++i) { - auto h = (buf[4 * i] << 24) | (buf[4 * i + 1] << 16) | - (buf[4 * i + 2] << 8) | buf[4 * i + 3]; + auto h = (static_cast(buf[4 * i]) << 24) | + (static_cast(buf[4 * i + 1]) << 16) | + (static_cast(buf[4 * i + 2]) << 8) | + static_cast(buf[4 * i + 3]); res.emplace_back(idx, h); }