]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
encoding: reset optional<> if it is uninitialized 17624/head
authorKefu Chai <kchai@redhat.com>
Fri, 8 Sep 2017 11:28:09 +0000 (19:28 +0800)
committerKefu Chai <kchai@redhat.com>
Mon, 11 Sep 2017 03:07:57 +0000 (11:07 +0800)
* should reset it, in case we reuse it after initializing it.
* initialize the value of `p` using the C++11 style initializer, so it
  is zero-initialized.
* revert 2a83ef3c which disables a warning of:
 ./include/encoding.h:317:7: warning: 't' may be used uninitialized in
    this function [-Wmaybe-uninitialized]
 where the `t` is the temporary variable for initializing the value of
 `p`.

Signed-off-by: Kefu Chai <kchai@redhat.com>
(cherry picked from commit 0363236dc754180a0215a818d58587943f84fb53)

src/include/encoding.h

index f7ee5d118285cf17e03ca83e028dade11d5c1171..5015e19024b2d274d79725a2a1376146d65ecb12 100644 (file)
@@ -297,16 +297,16 @@ inline void encode(const boost::optional<T> &p, bufferlist &bl)
 #pragma GCC diagnostic ignored "-Wpragmas"
 #pragma GCC diagnostic push
 #pragma GCC diagnostic ignored "-Wuninitialized"
-#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
 template<typename T>
 inline void decode(boost::optional<T> &p, bufferlist::iterator &bp)
 {
   __u8 present;
   ::decode(present, bp);
   if (present) {
-    T t;
-    p = t;
+    p = T{};
     decode(p.get(), bp);
+  } else {
+    p = boost::none;
   }
 }
 #pragma GCC diagnostic pop