]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
messages: fix out of range assertion
authorJohn Spray <john.spray@redhat.com>
Thu, 6 Oct 2016 10:20:47 +0000 (12:20 +0200)
committerJohn Spray <john.spray@redhat.com>
Fri, 21 Oct 2016 10:38:19 +0000 (11:38 +0100)
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>
src/common/perf_counters.h
src/messages/MMgrReport.h

index dc3a21a68a846997f753e9ddec8bfa8f4484e91b..61e5f4c4ec7029569abf52273932c1666b187a42 100644 (file)
@@ -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,
index 907cf47e014e96aa9cff5442133cca5e9bfc08ac..21eb7c6acdb41f4c6dea1a0e245bb7ee11c2a631 100644 (file)
@@ -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);
   }