]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
common: duplicate an encoding macro to suppress warnings.
authorRadoslaw Zarzynski <rzarzyns@redhat.com>
Wed, 19 Sep 2018 16:33:10 +0000 (18:33 +0200)
committerRadoslaw Zarzynski <rzarzyns@redhat.com>
Sat, 6 Oct 2018 10:32:34 +0000 (12:32 +0200)
It looks that after deprecating the backward iterations over
bufferlist, the `DECODE_START_LEGACY_COMPAT_LEN` can't reuse
the `__DECODE_START_LEGACY_COMPAT_LEN` with `skip_v=0`. This
will have led to huge number of warning:

  src/include/encoding.h:1285:28: warning: comparison of
  unsigned expression < 0 is always false

Signed-off-by: Radoslaw Zarzynski <rzarzyns@redhat.com>
src/include/encoding.h

index 65f8222f98f8c2ce7111195d2957cc657f5ba2fb..d1686d92dbe6de37b50ecbe0729a8ced5b2a8a10 100644 (file)
@@ -1284,6 +1284,8 @@ decode(std::array<T, N>& v, bufferlist::const_iterator& p)
   unsigned struct_end = bl.get_off() + struct_len;                     \
   do {
 
+/* BEWARE: any change to this macro MUST be also reflected in the duplicative
+ * DECODE_START_LEGACY_COMPAT_LEN! */
 #define __DECODE_START_LEGACY_COMPAT_LEN(v, compatv, lenv, skip_v, bl) \
   using ::ceph::decode;                                                        \
   __u8 struct_v;                                                       \
@@ -1322,8 +1324,30 @@ decode(std::array<T, N>& v, bufferlist::const_iterator& p)
  * @param lenv oldest version that includes a __u32 length wrapper
  * @param bl bufferlist::iterator containing the encoded data
  */
+
+/* BEWARE: this is duplication of __DECODE_START_LEGACY_COMPAT_LEN which
+ * MUST be changed altogether. For the rationale behind code duplication,
+ * please `git blame` and refer to the commit message. */
 #define DECODE_START_LEGACY_COMPAT_LEN(v, compatv, lenv, bl)           \
-  __DECODE_START_LEGACY_COMPAT_LEN(v, compatv, lenv, 0u, bl)
+  using ::ceph::decode;                                                        \
+  __u8 struct_v;                                                       \
+  decode(struct_v, bl);                                                        \
+  if (struct_v >= compatv) {                                           \
+    __u8 struct_compat;                                                        \
+    decode(struct_compat, bl);                                         \
+    if (v < struct_compat)                                             \
+      throw buffer::malformed_input(DECODE_ERR_OLDVERSION(             \
+       __PRETTY_FUNCTION__, v, struct_compat));                        \
+  }                                                                    \
+  unsigned struct_end = 0;                                             \
+  if (struct_v >= lenv) {                                              \
+    __u32 struct_len;                                                  \
+    decode(struct_len, bl);                                            \
+    if (struct_len > bl.get_remaining())                               \
+      throw buffer::malformed_input(DECODE_ERR_PAST(__PRETTY_FUNCTION__)); \
+    struct_end = bl.get_off() + struct_len;                            \
+  }                                                                    \
+  do {
 
 /**
  * start a decoding block with legacy support for older encoding schemes