From bb66b051edccbc6fd21957e7e79e3c19a39adae2 Mon Sep 17 00:00:00 2001 From: Duarte Nunes Date: Sun, 11 Dec 2016 17:50:43 +0100 Subject: [PATCH] dht: Make i_partitioner::tri_compare memory safe This patch fixes a typo in i_partitioner::tri_compare() where we were using std::max instead of std::min, thus avoiding accessing random memory and getting random results. Signed-off-by: Duarte Nunes Message-Id: <20161211165043.17816-1-duarte@scylladb.com> --- dht/i_partitioner.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dht/i_partitioner.cc b/dht/i_partitioner.cc index ac001beba1..688c411088 100644 --- a/dht/i_partitioner.cc +++ b/dht/i_partitioner.cc @@ -113,7 +113,7 @@ static inline unsigned char get_byte(bytes_view b, size_t off) { } int i_partitioner::tri_compare(const token& t1, const token& t2) const { - size_t sz = std::max(t1._data.size(), t2._data.size()); + size_t sz = std::min(t1._data.size(), t2._data.size()); for (size_t i = 0; i < sz; i++) { auto b1 = get_byte(t1._data, i);