From 6c9076fdd7fba9cbc91c8d88813da2bad0d50369 Mon Sep 17 00:00:00 2001 From: Duarte Nunes Date: Wed, 27 Jul 2016 12:43:21 +0200 Subject: [PATCH] composite_view: Fix is_static composite_view's is_static function is wrong because: 1) It doesn't guard against the composite being a compound; 2) Doesn't deal with widening due to integral promotions and consequent sign extension. This patch fixes this by ensuring there's only one correct implementation of is_static, to avoid code duplication and enforce test coverage. Signed-off-by: Duarte Nunes Message-Id: <1469616205-4550-2-git-send-email-duarte@scylladb.com> --- compound_compat.hh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/compound_compat.hh b/compound_compat.hh index 49f9779653..bf5a66d47f 100644 --- a/compound_compat.hh +++ b/compound_compat.hh @@ -414,8 +414,12 @@ public: return _bytes.empty(); } + static bool is_static(bytes_view bytes, bool is_compound) { + return is_compound && bytes.size() > 2 && (bytes.at(0) & bytes.at(1) & 0xff) == 0xff; + } + bool is_static() const { - return _is_compound && size() > 2 && (_bytes.at(0) & _bytes.at(1) & 0xff) == 0xff; + return is_static(_bytes, _is_compound); } bool is_compound() const { @@ -514,7 +518,7 @@ public: } bool is_static() const { - return size() > 2 && (_bytes.at(0) & _bytes.at(1)) == 0xff; + return composite::is_static(_bytes, _is_compound); } explicit operator bytes_view() const {