fix some issues from cppchecker/clang++
v2 cover fix some issues from cppchecker/clang++
These patches fix some issues found by using cppchecker/clang++.
---
v2: - [4/8]: don't copy append_buffer and last_p
- [7/8]: use C++ initalize syntax for constructor
Danny Al-Gaaf (8):
WorkQueue.h: fix cast
ceph_crypto.cc: remove unused shutdown() outside crypto ifdef's obj_bencher.cc: use vector instead of VLA's include/buffer.h: fix operator=
include/types.h: change operator<< function parameter include/xlist.h: fix C-style pointer casting messages/MOSDRepScrub.h: initialize member variable in constructor msg/Message.h: fix C-style pointer casting
src/common/WorkQueue.h | 4 ++-- src/common/ceph_crypto.cc | 1 - src/common/obj_bencher.cc | 13 +++++++------ src/include/buffer.h | 8 +++++--- src/include/types.h | 2 +- src/include/xlist.h | 6 +++--- src/messages/MOSDRepScrub.h | 5 ++++- src/msg/Message.h | 4 ++-- 8 files changed, 24 insertions(+), 19 deletions(-)
Signature · 1 line
1.8.1.2
PATCH v2 1/8 WorkQueue.h: fix cast
Replace C-style pointer casting with correct static_cast<>().
--- src/common/WorkQueue.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
src/common/WorkQueue.h +2 -2
@@ -251,10 +251,10 @@ public:return (void *)_dequeue (); } void _void_process(void *p, TPHandle &handle) { -_process ((T *)p, handle); + _process(static_cast<T *>(p), handle); }void _void_process_finish (void *p) { -_process_finish ((T *)p); + _process_finish(static_cast<T *>(p)); } public:
Signature · 1 line
1.8.1.2
PATCH v2 2/8 ceph_crypto.cc: remove unused shutdown() outside crypto ifdef's
In reply to Danny Al-GaafFix "out-of-line declaration of a member must be a definition [-Wout-of-line-declaration]". Remove ceph::crypto::shutdown() outside the crypto related ifdef's. Without nss or cryptopp configure will fail anyways.
--- src/common/ceph_crypto.cc | 1 - 1 file changed, 1 deletion(-)
src/common/ceph_crypto.cc +0 -1
@@ -20,7 +20,6 @@ #include <pthread.h> #include <stdlib.h> -void ceph::crypto::shutdown(); #ifdef USE_CRYPTOPP void ceph::crypto::init(CephContext *cct)
Signature · 1 line
1.8.1.2
PATCH v2 3/8 obj_bencher.cc: use vector instead of VLA's
In reply to Danny Al-GaafFix "variable length array of non-POD element type" error. (-Wvla)
--- src/common/obj_bencher.cc | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)
src/common/obj_bencher.cc +7 -6
@@ -25,6 +25,7 @@ #include <stdlib.h> #include <time.h> #include <sstream> +#include <vector> const std::string BENCH_LASTRUN_METADATA = "benchmark_last_metadata";
@@ -305,11 +306,11 @@ int ObjBencher::write_bench(int secondsToRun, int concurrentios) { std::string prefix = generate_object_prefix(); out(cout) << "Object prefix: " << prefix << std::endl; - std::string name[concurrentios]; + std::vector<string> name(concurrentios); std::string newName; bufferlist* contents[concurrentios]; double total_latency = 0; - utime_t start_times[concurrentios]; + std::vector<utime_t> start_times(concurrentios); utime_t stopTime; int r = 0; bufferlist b_write;
@@ -493,13 +494,13 @@ int ObjBencher::write_bench(int secondsToRun, int concurrentios) { int ObjBencher::seq_read_bench(int seconds_to_run, int num_objects, int concurrentios, int pid) { lock_cond lc(&lock); - std::string name[concurrentios]; + std::vector<string> name(concurrentios); std::string newName; bufferlist* contents[concurrentios]; int index[concurrentios]; int errors = 0; utime_t start_time; - utime_t start_times[concurrentios]; + std::vector<utime_t> start_times(concurrentios); utime_t time_to_run; time_to_run.set_from_double(seconds_to_run); double total_latency = 0;
@@ -705,7 +706,7 @@ int ObjBencher::clean_up(const std::string& prefix, int concurrentios) { int ObjBencher::clean_up(int num_objects, int prevPid, int concurrentios) { lock_cond lc(&lock); - std::string name[concurrentios]; + std::vector<string> name(concurrentios); std::string newName; int r = 0; utime_t runtime;
@@ -865,7 +866,7 @@ bool ObjBencher::more_objects_matching_prefix(const std::string& prefix, std::li int ObjBencher::clean_up_slow(const std::string& prefix, int concurrentios) { lock_cond lc(&lock); - std::string name[concurrentios]; + std::vector<string> name(concurrentios); std::string newName; int r = 0; utime_t runtime;
Signature · 1 line
1.8.1.2
PATCH v2 4/8 include/buffer.h: fix operator=
In reply to Danny Al-GaafFix operator=: return "iterator&" instead of 'iterator'. Check if 'this' equals 'other' before set anything.
--- src/include/buffer.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
src/include/buffer.h +5 -3
@@ -248,7 +248,7 @@ public:p (other.p), p_off(other.p_off) {} - iterator operator=(const iterator& other) { + iterator& operator=(const iterator& other) {if (this != &other) { bl = other.bl; ls = other.ls;
@@ -305,8 +305,10 @@ public: list(const list& other) : _buffers(other._buffers), _len(other._len), last_p(this) { } list& operator= (const list& other) { - _buffers = other._buffers; - _len = other._len; +if (this != &other) { + _buffers = other._buffers; + _len = other._len; + }return *this; }
Signature · 1 line
1.8.1.2
PATCH v2 5/8 include/types.h: change operator<< function parameter
In reply to Danny Al-GaafFix "Function parameter 'v' should be passed by reference." from cppchecker. Use 'const pair<A,B>& v' similar to the other operator<< in this file.
--- src/include/types.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
src/include/types.h +1 -1
@@ -120,7 +120,7 @@ namespace __gnu_cxx {// -- io helpers -- template<class A, class B> -inline ostream& operator<<(ostream& out, const pair<A,B> v) { +inline ostream& operator<<(ostream& out, const pair<A,B>& v) {return out << v.first <<"," << v.second; }
Signature · 1 line
1.8.1.2
PATCH v2 6/8 include/xlist.h: fix C-style pointer casting
In reply to Danny Al-GaafReplace C-style pointer casting with correct static_cast<>().
--- src/include/xlist.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
src/include/xlist.h +3 -3
@@ -132,8 +132,8 @@ public:assert ((bool )_front == (bool )_size); } -T front () {return (T )_front->_item; } -T back () {return (T )_back->_item; } +T front () {return static_cast<T >(_front->_item); } +T back () {return static_cast<T >(_back->_item); }void pop_front () {assert (!empty ());
@@ -149,7 +149,7 @@ public:item *cur; public: iterator(item *i = 0) : cur(i) {} - T operator*() { return (T)cur->_item; } + T operator*() { return static_cast<T>(cur->_item); } iterator& operator++() {assert (cur);assert (cur->_list);
Signature · 1 line
1.8.1.2
PATCH v2 7/8 messages/MOSDRepScrub.h: initialize member variable in constructor
In reply to Danny Al-GaafInitialize chunky and deep bool member variables in the constructor with false.
--- src/messages/MOSDRepScrub.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
src/messages/MOSDRepScrub.h +4 -1
@@ -36,7 +36,10 @@ struct MOSDRepScrub : public Message {hobject_t end;// upper bound of scrub, exclusive bool deep;// true if scrub should be deep - MOSDRepScrub() : Message(MSG_OSD_REP_SCRUB, HEAD_VERSION, COMPAT_VERSION) { } + MOSDRepScrub() : Message(MSG_OSD_REP_SCRUB, HEAD_VERSION, COMPAT_VERSION), +chunky (false), + deep(false) { } + MOSDRepScrub(pg_t pgid, eversion_t scrub_from, eversion_t scrub_to, epoch_t map_epoch) : Message(MSG_OSD_REP_SCRUB, HEAD_VERSION, COMPAT_VERSION),
Signature · 1 line
1.8.1.2
PATCH v2 8/8 msg/Message.h: fix C-style pointer casting
In reply to Danny Al-GaafReplace C-style pointer casting with correct static_cast<>().
--- src/msg/Message.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
src/msg/Message.h +2 -2
@@ -188,7 +188,7 @@ public: }Connection *get () { - return (Connection *)RefCountedObject::get(); + return static_cast<Connection *>(RefCountedObject::get()); }void set_priv (RefCountedObject *o) {
@@ -329,7 +329,7 @@ public: }Message *get () { - return (Message *)RefCountedObject::get(); + return static_cast<Message *>(RefCountedObject::get()); } protected:
Signature · 1 line
1.8.1.2
THanks-
I just pulled this in, along with the rbd-fuse fix.
Quoted 30 lines · Danny Al-Gaaf
These patches fix some issues found by using cppchecker/clang++.
---
v2: - [4/8]: don't copyappend_bufferandlast_p
- [7/8]: use C++ initalize syntax for constructorDanny Al-Gaaf (8):
WorkQueue.h: fix cast
ceph_crypto.cc: remove unusedshutdown()outside crypto ifdef's obj_bencher.cc: use vector instead of VLA'sinclude/buffer.h: fix operator=
include/types.h: change operator<< function parameterinclude/xlist.h: fix C-style pointer castingmessages/MOSDRepScrub.h: initialize member variable in constructormsg/Message.h: fix C-style pointer castingsrc/common/WorkQueue.h | 4 ++-- src/common/ceph_crypto.cc | 1 - src/common/obj_bencher.cc | 13 +++++++------ src/include/buffer.h | 8 +++++--- src/include/types.h | 2 +- src/include/xlist.h | 6 +++--- src/messages/MOSDRepScrub.h | 5 ++++- src/msg/Message.h | 4 ++-- 8 files changed, 24 insertions(+), 19 deletions(-)Signature · 1 line
1.8.1.2