From: John Spray Date: Tue, 6 May 2014 15:49:53 +0000 (-0700) Subject: encoding: make .size() to __u32 cast explicit X-Git-Tag: v0.81~43^2~4 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=3fd871270b888c08811d03ab0ae11221a2e38a07;p=ceph.git encoding: make .size() to __u32 cast explicit Caught by clang warning that this is a conversion from "unsigned long" to "unsigned int" which can lose precision. However, this is the conversion we want because our serialization format defines sizes as 4 bytes. Signed-off-by: John Spray --- diff --git a/src/include/encoding.h b/src/include/encoding.h index 434d1588321e..d19b60e9eeae 100644 --- a/src/include/encoding.h +++ b/src/include/encoding.h @@ -372,7 +372,7 @@ inline void encode(const std::list& ls, bufferlist& bl) en = n; bl.copy_in(pos, sizeof(en), (char*)&en); } else { - __u32 n = ls.size(); // FIXME: this is slow on a list. + __u32 n = (__u32)(ls.size()); // FIXME: this is slow on a list. encode(n, bl); for (typename std::list::const_iterator p = ls.begin(); p != ls.end(); ++p) encode(*p, bl); @@ -407,7 +407,7 @@ inline void encode(const std::list >& ls, bufferlist& bl) en = n; bl.copy_in(pos, sizeof(en), (char*)&en); } else { - __u32 n = ls.size(); // FIXME: this is slow on a list. + __u32 n = (__u32)(ls.size()); // FIXME: this is slow on a list. encode(n, bl); for (typename std::list >::const_iterator p = ls.begin(); p != ls.end(); ++p) encode(**p, bl); @@ -430,7 +430,7 @@ inline void decode(std::list >& ls, bufferlist::iterator& p) template inline void encode(const std::set& s, bufferlist& bl) { - __u32 n = s.size(); + __u32 n = (__u32)(s.size()); encode(n, bl); for (typename std::set::const_iterator p = s.begin(); p != s.end(); ++p) encode(*p, bl); @@ -471,7 +471,7 @@ inline void decode(std::vector& v, bufferlist::iterator& p) template inline void encode(const std::vector& v, bufferlist& bl, uint64_t features) { - __u32 n = v.size(); + __u32 n = (__u32)(v.size()); encode(n, bl); for (typename std::vector::const_iterator p = v.begin(); p != v.end(); ++p) encode(*p, bl, features); @@ -479,7 +479,7 @@ inline void encode(const std::vector& v, bufferlist& bl, uint64_t features) template inline void encode(const std::vector& v, bufferlist& bl) { - __u32 n = v.size(); + __u32 n = (__u32)(v.size()); encode(n, bl); for (typename std::vector::const_iterator p = v.begin(); p != v.end(); ++p) encode(*p, bl); @@ -512,7 +512,7 @@ inline void decode_nohead(int len, std::vector& v, bufferlist::iterator& p) template inline void encode(const std::vector >& v, bufferlist& bl) { - __u32 n = v.size(); + __u32 n = (__u32)(v.size()); encode(n, bl); for (typename std::vector >::const_iterator p = v.begin(); p != v.end(); ++p) if (*p) @@ -561,7 +561,7 @@ inline void decode(std::map& m, bufferlist::iterator& p) template inline void encode(const std::map& m, bufferlist& bl) { - __u32 n = m.size(); + __u32 n = (__u32)(m.size()); encode(n, bl); for (typename std::map::const_iterator p = m.begin(); p != m.end(); ++p) { encode(p->first, bl); @@ -571,7 +571,7 @@ inline void encode(const std::map& m, bufferlist& bl) template inline void encode(const std::map& m, bufferlist& bl, uint64_t features) { - __u32 n = m.size(); + __u32 n = (__u32)(m.size()); encode(n, bl); for (typename std::map::const_iterator p = m.begin(); p != m.end(); ++p) { encode(p->first, bl, features); @@ -632,7 +632,7 @@ inline void decode_nohead(int n, std::map& m, bufferlist::iterator& p) template inline void encode(const std::multimap& m, bufferlist& bl) { - __u32 n = m.size(); + __u32 n = (__u32)(m.size()); encode(n, bl); for (typename std::multimap::const_iterator p = m.begin(); p != m.end(); ++p) { encode(p->first, bl); @@ -657,7 +657,7 @@ inline void decode(std::multimap& m, bufferlist::iterator& p) template inline void encode(const unordered_map& m, bufferlist& bl) { - __u32 n = m.size(); + __u32 n = (__u32)(m.size()); encode(n, bl); for (typename unordered_map::const_iterator p = m.begin(); p != m.end(); ++p) { encode(p->first, bl); @@ -681,7 +681,7 @@ inline void decode(unordered_map& m, bufferlist::iterator& p) template inline void encode(const ceph::unordered_set& m, bufferlist& bl) { - __u32 n = m.size(); + __u32 n = (__u32)(m.size()); encode(n, bl); for (typename ceph::unordered_set::const_iterator p = m.begin(); p != m.end(); ++p) encode(*p, bl);