From ace4abbee5c3f91ff025b8348b31ada423181c24 Mon Sep 17 00:00:00 2001 From: John Spray Date: Thu, 6 Oct 2016 12:20:47 +0200 Subject: [PATCH] messages: fix out of range assertion 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 --- src/common/perf_counters.h | 2 +- src/messages/MMgrReport.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/common/perf_counters.h b/src/common/perf_counters.h index dc3a21a68a8..61e5f4c4ec7 100644 --- a/src/common/perf_counters.h +++ b/src/common/perf_counters.h @@ -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, diff --git a/src/messages/MMgrReport.h b/src/messages/MMgrReport.h index 907cf47e014..21eb7c6acdb 100644 --- a/src/messages/MMgrReport.h +++ b/src/messages/MMgrReport.h @@ -36,7 +36,7 @@ public: ::encode(path, bl); ::encode(description, bl); ::encode(nick, bl); - assert(type < 256); + static_assert(sizeof(type) == 1, "perfcounter_type_d must be one byte"); ::encode((uint8_t)type, bl); ENCODE_FINISH(bl); }