From 2f9e636618297557ed2ff69b7386253f1323dcfc Mon Sep 17 00:00:00 2001 From: theoreticalbts Date: Wed, 8 Jul 2015 15:00:46 -0400 Subject: [PATCH] db_maint.cpp: Avoid implementation-defined ordering when votable objects tie for votes --- libraries/chain/db_maint.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libraries/chain/db_maint.cpp b/libraries/chain/db_maint.cpp index 1fd4bf98..05209ef1 100644 --- a/libraries/chain/db_maint.cpp +++ b/libraries/chain/db_maint.cpp @@ -44,7 +44,11 @@ vector> database::sort [](const ObjectType& o) { return std::cref(o); }); std::partial_sort(refs.begin(), refs.begin() + count, refs.end(), [this](const ObjectType& a, const ObjectType& b)->bool { - return _vote_tally_buffer[a.vote_id] > _vote_tally_buffer[b.vote_id]; + share_type oa_vote = _vote_tally_buffer[a.vote_id]; + share_type ob_vote = _vote_tally_buffer[b.vote_id]; + if( oa_vote != ob_vote ) + return oa_vote > ob_vote; + return a.vote_id < b.vote_id; }); refs.resize(count, refs.front());