Skip to content

Commit

Permalink
messages: fix out of range assertion
Browse files Browse the repository at this point in the history
When clang uses an 8 bit type for the enum, it
complains (out of range) if comparing <256,
and complains (tautological) if comparing <=256.

Avoid this by explicitly making the enum an
uint8_t, and just asserting that that it has
that size at the point that we assume so for
the encoding (in case someone modified the
type definition without checking how it was used).

Signed-off-by: John Spray <john.spray@redhat.com>
  • Loading branch information
John Spray committed Oct 19, 2016
1 parent a1fd258 commit 103c2cf
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/common/perf_counters.h
Expand Up @@ -32,7 +32,7 @@ class CephContext;
class PerfCountersBuilder;
class PerfCountersCollectionTest;

enum perfcounter_type_d
enum perfcounter_type_d : uint8_t
{
PERFCOUNTER_NONE = 0,
PERFCOUNTER_TIME = 0x1,
Expand Down
2 changes: 1 addition & 1 deletion src/messages/MMgrReport.h
Expand Up @@ -36,7 +36,7 @@ class PerfCounterType
::encode(path, bl);
::encode(description, bl);
::encode(nick, bl);
assert(type < 256);
static_assert(sizeof(type) == 1); // enum type declared as uint8_t
::encode((uint8_t)type, bl);
ENCODE_FINISH(bl);
}
Expand Down

0 comments on commit 103c2cf

Please sign in to comment.