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 <duarte@scylladb.com>
Message-Id: <1469616205-4550-2-git-send-email-duarte@scylladb.com>
This commit is contained in:
Duarte Nunes
2016-07-27 12:43:21 +02:00
committed by Tomasz Grabiec
parent 27f6c0d62b
commit 6c9076fdd7

View File

@@ -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 {