Merge pull request #22007 from dalgaaf/wip-da-SCA-20180514

rgw, common: Fixes SCA issues

Reviewed-by: Kefu Chai <kchai@redhat.com>
This commit is contained in:
Kefu Chai 2018-06-28 23:39:55 +08:00 committed by GitHub
commit d3a64e92d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 38 additions and 45 deletions

View File

@ -2258,8 +2258,8 @@ int buffer::list::write_file(const char *fn, int mode)
static int do_writev(int fd, struct iovec *vec, uint64_t offset, unsigned veclen, unsigned bytes)
{
ssize_t r = 0;
while (bytes > 0) {
ssize_t r = 0;
#ifdef HAVE_PWRITEV
r = ::pwritev(fd, vec, veclen, offset);
#else
@ -2492,9 +2492,8 @@ void buffer::list::hexdump(std::ostream &out, bool trailing_newline) const
unsigned per = 16;
bool was_zeros = false, did_star = false;
for (unsigned o=0; o<length(); o += per) {
bool row_is_zeros = false;
if (o + per < length()) {
row_is_zeros = true;
bool row_is_zeros = true;
for (unsigned i=0; i<per && o+i<length(); i++) {
if ((*this)[o+i]) {
row_is_zeros = false;

View File

@ -218,8 +218,8 @@ uint32_t ceph_crc32c_zeros(uint32_t crc, unsigned len)
len = len >> 4;
range = 4;
while (len != 0) {
uint32_t crc1 = 0;
if ((len & 1) == 1) {
uint32_t crc1 = 0;
uint32_t* ptr = crc_turbo_table/*.val*/[range];
while (crc != 0) {
uint32_t mask = ~((crc & 1) - 1);

View File

@ -107,7 +107,7 @@ protected:
ostream& out(ostream& os);
ostream& out(ostream& os, utime_t& t);
public:
explicit ObjBencher(CephContext *cct_) : show_time(false), cct(cct_), lock("ObjBencher::lock") {}
explicit ObjBencher(CephContext *cct_) : show_time(false), cct(cct_), lock("ObjBencher::lock"), data() {}
virtual ~ObjBencher() {}
int aio_bench(
int operation, int secondsToRun,

View File

@ -50,12 +50,10 @@ class LZ4Compressor : public Compressor {
int pos = 0;
const char *data;
unsigned num = src.get_num_buffers();
uint32_t origin_len;
int compressed_len;
encode((uint32_t)num, dst);
while (left) {
origin_len = p.get_ptr_and_advance(left, &data);
compressed_len = LZ4_compress_fast_continue(
uint32_t origin_len = p.get_ptr_and_advance(left, &data);
int compressed_len = LZ4_compress_fast_continue(
&lz4_stream, data, outptr.c_str()+pos, origin_len,
outptr.length()-pos, 1);
if (compressed_len <= 0)

View File

@ -1093,8 +1093,8 @@ public:
static void bound_encode(const container& s, size_t& p, uint64_t f = 0) {
if constexpr (traits::bounded) {
if constexpr (traits::featured) {
size_t elem_size = 0;
if (!s.empty()) {
size_t elem_size = 0;
denc(*s.begin(), elem_size, f);
p += elem_size * s.size();
}

View File

@ -15,7 +15,7 @@ struct ImageDispatchSpec<I>::SendVisitor
: public boost::static_visitor<void> {
ImageDispatchSpec* spec;
SendVisitor(ImageDispatchSpec* spec)
explicit SendVisitor(ImageDispatchSpec* spec)
: spec(spec) {
}

View File

@ -54,7 +54,7 @@ struct ImageRequestWQ<I>::C_AcquireLock : public Context {
template <typename I>
struct ImageRequestWQ<I>::C_BlockedWrites : public Context {
ImageRequestWQ *work_queue;
C_BlockedWrites(ImageRequestWQ *_work_queue)
explicit C_BlockedWrites(ImageRequestWQ *_work_queue)
: work_queue(_work_queue) {
}

View File

@ -644,11 +644,11 @@ BaseMgrModule_init(BaseMgrModule *self, PyObject *args, PyObject *kwds)
return -1;
}
self->py_modules = (ActivePyModules*)PyCapsule_GetPointer(
py_modules_capsule, nullptr);
self->py_modules = static_cast<ActivePyModules*>(PyCapsule_GetPointer(
py_modules_capsule, nullptr));
assert(self->py_modules);
self->this_module = (ActivePyModule*)PyCapsule_GetPointer(
this_module_capsule, nullptr);
self->this_module = static_cast<ActivePyModule*>(PyCapsule_GetPointer(
this_module_capsule, nullptr));
assert(self->this_module);
return 0;

View File

@ -47,8 +47,8 @@ BaseMgrStandbyModule_init(BaseMgrStandbyModule *self, PyObject *args, PyObject *
return -1;
}
self->this_module = (StandbyPyModule*)PyCapsule_GetPointer(
this_module_capsule, nullptr);
self->this_module = static_cast<StandbyPyModule*>(PyCapsule_GetPointer(
this_module_capsule, nullptr));
assert(self->this_module);
return 0;

View File

@ -523,7 +523,7 @@ bool Mgr::ms_dispatch(Message *m)
m->put();
break;
case MSG_SERVICE_MAP:
handle_service_map((MServiceMap*)m);
handle_service_map(static_cast<MServiceMap*>(m));
py_module_registry->notify_all("service_map", "");
m->put();
break;

View File

@ -339,8 +339,7 @@ int MonMap::build_from_host_list(std::string hostlist, const std::string &prefix
}
// maybe they passed us a DNS-resolvable name
char *hosts = NULL;
hosts = resolve_addrs(hostlist.c_str());
char *hosts = resolve_addrs(hostlist.c_str());
if (!hosts)
return -EINVAL;
bool success = parse_ip_port_vec(hosts, addrs);

View File

@ -3024,7 +3024,6 @@ int process_pg_map_command(
cmd_putval(g_ceph_context, cmdmap, "pool", pool);
}
int r = 0;
stringstream ds;
if (prefix == "pg stat") {
if (f) {
@ -3174,12 +3173,12 @@ int process_pg_map_command(
cmd_getval(g_ceph_context, cmdmap, "threshold", threshold,
g_conf->get_val<int64_t>("mon_pg_stuck_threshold"));
r = pg_map.dump_stuck_pg_stats(ds, f, (int)threshold, stuckop_vec);
odata->append(ds);
if (r < 0)
if (pg_map.dump_stuck_pg_stats(ds, f, (int)threshold, stuckop_vec) < 0) {
*ss << "failed";
else
} else {
*ss << "ok";
}
odata->append(ds);
return 0;
}

View File

@ -218,7 +218,7 @@ class DPDKWorker : public Worker {
};
std::unique_ptr<Impl> _impl;
virtual void initialize();
virtual void initialize() override;
void set_ipv4_packet_filter(ip_packet_filter* filter) {
_impl->_inet.set_packet_filter(filter);
}
@ -245,7 +245,7 @@ class DPDKStack : public NetworkStack {
funcs.resize(cct->_conf->ms_async_max_op_threads);
}
virtual bool support_zero_copy_read() const override { return true; }
virtual bool support_local_listen_table() const { return true; }
virtual bool support_local_listen_table() const override { return true; }
virtual void spawn_worker(unsigned i, std::function<void ()> &&func) override;
virtual void join_worker(unsigned i) override {

View File

@ -118,7 +118,7 @@ class ipv4_tcp final : public ip_protocol {
public:
ipv4_tcp(ipv4& inet, EventCenter *c);
~ipv4_tcp();
virtual void received(Packet p, ipv4_address from, ipv4_address to);
virtual void received(Packet p, ipv4_address from, ipv4_address to) override;
virtual bool forward(forward_hash& out_hash_data, Packet& p, size_t off) override;
friend class ipv4;
};
@ -167,7 +167,7 @@ class ipv4_icmp final : public ip_protocol {
icmp _icmp;
public:
ipv4_icmp(CephContext *c, ipv4& inet) : cct(c), _inet_l4(inet), _icmp(c, _inet_l4) {}
virtual void received(Packet p, ipv4_address from, ipv4_address to) {
virtual void received(Packet p, ipv4_address from, ipv4_address to) override {
_icmp.received(std::move(p), from, to);
}
friend class ipv4;

View File

@ -39,8 +39,8 @@
#undef dout_prefix
#define dout_prefix *_dout << "net "
interface::interface(CephContext *c, std::shared_ptr<DPDKDevice> dev, EventCenter *center)
: cct(c), _dev(dev),
interface::interface(CephContext *cct, std::shared_ptr<DPDKDevice> dev, EventCenter *center)
: cct(cct), _dev(dev),
_rx(_dev->receive(
center->get_id(),
[center, this] (Packet p) {

View File

@ -117,7 +117,7 @@ class interface {
private:
int dispatch_packet(EventCenter *c, Packet p);
public:
explicit interface(CephContext *cct, std::shared_ptr<DPDKDevice> dev, EventCenter *c);
explicit interface(CephContext *cct, std::shared_ptr<DPDKDevice> dev, EventCenter *center);
ethernet_address hw_address() { return _hw_address; }
const struct hw_features& get_hw_features() const { return _hw_features; }
subscription<Packet, ethernet_address> register_l3(

View File

@ -430,7 +430,7 @@ bool RGWCoroutinesStack::collect(int *ret, RGWCoroutinesStack *skip_stack) /* re
static void _aio_completion_notifier_cb(librados::completion_t cb, void *arg)
{
((RGWAioCompletionNotifier *)arg)->cb();
(static_cast<RGWAioCompletionNotifier *>(arg))->cb();
}
RGWAioCompletionNotifier::RGWAioCompletionNotifier(RGWCompletionManager *_mgr, const rgw_io_id& _io_id, void *_user_data) : completion_mgr(_mgr),
@ -531,7 +531,7 @@ void RGWCoroutinesManager::handle_unblocked_stack(set<RGWCoroutinesStack *>& con
RGWCompletionManager::io_completion& io, int *blocked_count)
{
assert(lock.is_wlocked());
RGWCoroutinesStack *stack = (RGWCoroutinesStack *)io.user_info;
RGWCoroutinesStack *stack = static_cast<RGWCoroutinesStack *>(io.user_info);
if (context_stacks.find(stack) == context_stacks.end()) {
return;
}

View File

@ -2190,15 +2190,15 @@ public:
void execute() override {}
const char* name() const override { return "get_bucket_meta_search"; }
virtual RGWOpType get_type() { return RGW_OP_GET_BUCKET_META_SEARCH; }
virtual uint32_t op_mask() { return RGW_OP_TYPE_READ; }
virtual RGWOpType get_type() override { return RGW_OP_GET_BUCKET_META_SEARCH; }
virtual uint32_t op_mask() override { return RGW_OP_TYPE_READ; }
};
class RGWDelBucketMetaSearch : public RGWOp {
public:
RGWDelBucketMetaSearch() {}
int verify_permission();
int verify_permission() override;
void pre_exec() override;
void execute() override;

View File

@ -119,12 +119,10 @@ public:
RGWRados *store = info->store;
list<string> unfiltered_keys;
int ret = store->list_raw_objects_next(no_filter, max, info->ctx,
keys, truncated);
if (ret < 0 && ret != -ENOENT)
return ret;
return ret;
if (ret == -ENOENT) {
if (truncated)
*truncated = false;

View File

@ -211,7 +211,7 @@ class RGWOp_Set_Bucket_Quota : public RGWRESTOp {
public:
RGWOp_Set_Bucket_Quota() {}
int check_caps(RGWUserCaps& caps) {
int check_caps(RGWUserCaps& caps) override {
return caps.check_cap("buckets", RGW_CAP_WRITE);
}

View File

@ -41,7 +41,7 @@ class RGWOp_ZoneConfig_Get : public RGWRESTOp {
public:
RGWOp_ZoneConfig_Get() {}
int check_caps(RGWUserCaps& caps) {
int check_caps(RGWUserCaps& caps) override {
return caps.check_cap("admin", RGW_CAP_READ);
}
int verify_permission() override {

View File

@ -949,7 +949,7 @@ public:
}
void send_ready(const rgw_rest_obj& rest_obj) override {
RGWRESTStreamS3PutObj *r = (RGWRESTStreamS3PutObj *)req;
RGWRESTStreamS3PutObj *r = static_cast<RGWRESTStreamS3PutObj *>(req);
map<string, string> new_attrs;
if (!multipart.is_multipart) {
@ -1088,7 +1088,7 @@ public:
return set_cr_error(retcode);
}
if (!((RGWAWSStreamPutCRF *)out_crf.get())->get_etag(petag)) {
if (!(static_cast<RGWAWSStreamPutCRF *>(out_crf.get()))->get_etag(petag)) {
ldout(sync_env->cct, 0) << "ERROR: failed to get etag from PUT request" << dendl;
return set_cr_error(-EIO);
}