nghttpx: Explicitly cast to uint32_t for hash calculation

This commit is contained in:
Tatsuhiro Tsujikawa 2016-07-06 23:58:53 +09:00
parent ca39c71ac3
commit 30f26a2b9d
2 changed files with 7 additions and 3 deletions

View File

@ -687,7 +687,9 @@ uint32_t compute_affinity_from_ip(const StringRef &ip) {
return util::hash32(ip); return util::hash32(ip);
} }
return (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3]; return (static_cast<uint32_t>(buf[0]) << 24) |
(static_cast<uint32_t>(buf[1]) << 16) |
(static_cast<uint32_t>(buf[2]) << 8) | static_cast<uint32_t>(buf[3]);
} }
} // namespace } // namespace

View File

@ -2854,8 +2854,10 @@ int compute_affinity_hash(std::vector<AffinityHash> &res, size_t idx,
} }
for (int i = 0; i < 8; ++i) { for (int i = 0; i < 8; ++i) {
auto h = (buf[4 * i] << 24) | (buf[4 * i + 1] << 16) | auto h = (static_cast<uint32_t>(buf[4 * i]) << 24) |
(buf[4 * i + 2] << 8) | buf[4 * i + 3]; (static_cast<uint32_t>(buf[4 * i + 1]) << 16) |
(static_cast<uint32_t>(buf[4 * i + 2]) << 8) |
static_cast<uint32_t>(buf[4 * i + 3]);
res.emplace_back(idx, h); res.emplace_back(idx, h);
} }