From: John Spray Date: Thu, 6 Oct 2016 10:20:47 +0000 (+0200) Subject: messages: fix out of range assertion X-Git-Tag: v11.1.0~523^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F11345%2Fhead;p=ceph.git 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 --- 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); }