modify the code according to CodeCheck

Signed-off-by: liujialiang <liujialiang10@huawei.com>
This commit is contained in:
liujialiang
2021-12-24 16:57:46 +08:00
parent 6e157ef8f4
commit eb6a44d76f
14 changed files with 54 additions and 56 deletions
-1
View File
@@ -292,7 +292,6 @@ public:
bool WriteUint8Unaligned(uint8_t value); bool WriteUint8Unaligned(uint8_t value);
bool WriteUint16Unaligned(uint16_t value); bool WriteUint16Unaligned(uint16_t value);
bool ReadBoolUnaligned(); bool ReadBoolUnaligned();
bool ReadInt8Unaligned(int8_t &value); bool ReadInt8Unaligned(int8_t &value);
bool ReadInt16Unaligned(int16_t &value); bool ReadInt16Unaligned(int16_t &value);
+1 -1
View File
@@ -121,7 +121,7 @@ public:
unfinishedTaskCount_ = 0; unfinishedTaskCount_ = 0;
} }
virtual ~SafeBlockQueueTracking(){}; virtual ~SafeBlockQueueTracking() {};
virtual void Push(T const& elem) virtual void Push(T const& elem)
{ {
+1 -1
View File
@@ -43,7 +43,7 @@ public:
SortedVector(const std::vector<TYPE>& orivect); SortedVector(const std::vector<TYPE>& orivect);
virtual ~SortedVector(){}; virtual ~SortedVector() {};
// copy operator // copy operator
SortedVector<TYPE, AllowDuplicate>& operator=(const SortedVector<TYPE, false>& rhs); SortedVector<TYPE, AllowDuplicate>& operator=(const SortedVector<TYPE, false>& rhs);
SortedVector<TYPE, AllowDuplicate>& operator=(const SortedVector<TYPE, true>& rhs); SortedVector<TYPE, AllowDuplicate>& operator=(const SortedVector<TYPE, true>& rhs);
+1 -1
View File
@@ -46,7 +46,7 @@ public:
* others: wait(until event-trigger) * others: wait(until event-trigger)
*/ */
explicit Timer(const std::string& name, int timeoutMs = 1000); explicit Timer(const std::string& name, int timeoutMs = 1000);
virtual ~Timer(){} virtual ~Timer() {}
virtual uint32_t Setup(); virtual uint32_t Setup();
+2 -2
View File
@@ -14,10 +14,10 @@
*/ */
#include "directory_ex.h" #include "directory_ex.h"
#include "securec.h"
#include "unistd.h"
#include <dirent.h> #include <dirent.h>
#include <errno.h> #include <errno.h>
#include "securec.h"
#include "unistd.h"
#include "utils_log.h" #include "utils_log.h"
using namespace std; using namespace std;
+1 -1
View File
@@ -34,7 +34,7 @@ public:
EventHandler(const EventHandler&) = delete; EventHandler(const EventHandler&) = delete;
EventHandler& operator=(const EventHandler&&) = delete; EventHandler& operator=(const EventHandler&&) = delete;
EventHandler(const EventHandler&&) = delete; EventHandler(const EventHandler&&) = delete;
~EventHandler(){}; ~EventHandler() {};
int GetHandle() const { return (fd_); } int GetHandle() const { return (fd_); }
uint32_t Events() const { return (events_); } uint32_t Events() const { return (events_); }
+1 -1
View File
@@ -14,7 +14,6 @@
*/ */
#include "file_ex.h" #include "file_ex.h"
#include "directory_ex.h"
#include <fstream> #include <fstream>
#include <iostream> #include <iostream>
#include <algorithm> #include <algorithm>
@@ -25,6 +24,7 @@
#include <cstdio> #include <cstdio>
#include <securec.h> #include <securec.h>
#include <cstring> #include <cstring>
#include "directory_ex.h"
#include "utils_log.h" #include "utils_log.h"
using namespace std; using namespace std;
+1 -1
View File
@@ -696,7 +696,7 @@ bool Parcel::Read(T &value)
template <typename T> template <typename T>
T Parcel::Read() T Parcel::Read()
{ {
T lvalue{}; T lvalue {};
return Read<T>(lvalue) ? lvalue : 0; return Read<T>(lvalue) ? lvalue : 0;
} }
+11 -11
View File
@@ -34,7 +34,7 @@ WeakRefCounter::~WeakRefCounter()
void* WeakRefCounter::GetRefPtr() void* WeakRefCounter::GetRefPtr()
{ {
if ((cookie_ != nullptr) && (!refCounter_->IsRefPtrValid())){ if ((cookie_ != nullptr) && (!refCounter_->IsRefPtrValid())) {
cookie_ = nullptr; cookie_ = nullptr;
} }
return cookie_; return cookie_;
@@ -103,7 +103,7 @@ RefCounter::~RefCounter()
{ {
} }
int RefCounter::IncStrongRefCount(const void* /*objectId*/) int RefCounter::IncStrongRefCount(const void* /* objectId */)
{ {
int curCount = atomicStrong_.load(std::memory_order_relaxed); int curCount = atomicStrong_.load(std::memory_order_relaxed);
@@ -117,7 +117,7 @@ int RefCounter::IncStrongRefCount(const void* /*objectId*/)
return curCount; return curCount;
} }
int RefCounter::DecStrongRefCount(const void* /*objectId*/) int RefCounter::DecStrongRefCount(const void* /* objectId */)
{ {
int curCount = GetStrongRefCount(); int curCount = GetStrongRefCount();
if (curCount == INITIAL_PRIMARY_VALUE) { if (curCount == INITIAL_PRIMARY_VALUE) {
@@ -136,12 +136,12 @@ int RefCounter::GetStrongRefCount()
return atomicStrong_.load(std::memory_order_relaxed); return atomicStrong_.load(std::memory_order_relaxed);
} }
int RefCounter::IncWeakRefCount(const void* /*objectId*/) int RefCounter::IncWeakRefCount(const void* /* objectId */)
{ {
return atomicWeak_.fetch_add(1, std::memory_order_relaxed); return atomicWeak_.fetch_add(1, std::memory_order_relaxed);
} }
int RefCounter::DecWeakRefCount(const void* /*objectId*/) int RefCounter::DecWeakRefCount(const void* /* objectId */)
{ {
int curCount = GetWeakRefCount(); int curCount = GetWeakRefCount();
if (curCount > 0) { if (curCount > 0) {
@@ -237,7 +237,7 @@ RefBase::RefBase() : refs_(new RefCounter())
refs_->SetCallback(std::bind(&RefBase::RefPtrCallback, this)); refs_->SetCallback(std::bind(&RefBase::RefPtrCallback, this));
} }
RefBase::RefBase(const RefBase &/*other*/) RefBase::RefBase(const RefBase & /* other */)
{ {
refs_ = new RefCounter(); refs_ = new RefCounter();
if (refs_ != nullptr) { if (refs_ != nullptr) {
@@ -257,7 +257,7 @@ void RefBase::RefPtrCallback()
* RISK: If there is a reference count on the left of the equal sign, * RISK: If there is a reference count on the left of the equal sign,
* it may cause a reference count exception * it may cause a reference count exception
*/ */
RefBase &RefBase::operator=(const RefBase &/*other*/) RefBase &RefBase::operator=(const RefBase & /* other */)
{ {
if (refs_ != nullptr) { if (refs_ != nullptr) {
refs_->RemoveCallback(); refs_->RemoveCallback();
@@ -426,16 +426,16 @@ bool RefBase::IsExtendLifeTimeSet()
return refs_->IsLifeTimeExtended(); return refs_->IsLifeTimeExtended();
} }
void RefBase::OnFirstStrongRef(const void* /*objectId*/) void RefBase::OnFirstStrongRef(const void* /* objectId */)
{} {}
void RefBase::OnLastStrongRef(const void* /*objectId*/) void RefBase::OnLastStrongRef(const void* /* objectId */)
{} {}
void RefBase::OnLastWeakRef(const void* /*objectId*/) void RefBase::OnLastWeakRef(const void* /* objectId */)
{} {}
bool RefBase::OnAttemptPromoted(const void* /*objectId*/) bool RefBase::OnAttemptPromoted(const void* /* objectId */)
{ {
return true; return true;
} }
@@ -82,7 +82,7 @@ class IRemoteObject : public virtual RefBase {
public: public:
IRemoteObject() { ExtendObjectLifetime(); }; IRemoteObject() { ExtendObjectLifetime(); };
virtual bool IsProxyObject() = 0; virtual bool IsProxyObject() = 0;
~IRemoteObject(){}; ~IRemoteObject() {};
}; };
class RefBaseTestTracker : public RefBase { class RefBaseTestTracker : public RefBase {
@@ -205,7 +205,7 @@ public:
tracker->TrackObject(this); tracker->TrackObject(this);
tracker->TrackNewObject(this); tracker->TrackNewObject(this);
}; };
~IPCObjectProxy(){}; ~IPCObjectProxy() {};
void RefPtrCallback() override; void RefPtrCallback() override;
void OnLastStrongRef(const void *objectId) override; void OnLastStrongRef(const void *objectId) override;
void OnFirstStrongRef(const void *objectId) override; void OnFirstStrongRef(const void *objectId) override;
@@ -28,8 +28,8 @@ public:
void* GetObjAddr() { return (void*)this; } void* GetObjAddr() { return (void*)this; }
}; };
DelayedSingletonDeclearTest::~DelayedSingletonDeclearTest(){}; DelayedSingletonDeclearTest::~DelayedSingletonDeclearTest() {};
DelayedSingletonDeclearTest::DelayedSingletonDeclearTest(){}; DelayedSingletonDeclearTest::DelayedSingletonDeclearTest() {};
class SingletonDeclearTest { class SingletonDeclearTest {
DECLARE_SINGLETON(SingletonDeclearTest); DECLARE_SINGLETON(SingletonDeclearTest);
@@ -37,8 +37,8 @@ public:
void* GetObjAddr() { return (void*)this; } void* GetObjAddr() { return (void*)this; }
}; };
SingletonDeclearTest::~SingletonDeclearTest(){}; SingletonDeclearTest::~SingletonDeclearTest() {};
SingletonDeclearTest::SingletonDeclearTest(){}; SingletonDeclearTest::SingletonDeclearTest() {};
class SingletonTest: public Singleton<SingletonTest> { class SingletonTest: public Singleton<SingletonTest> {
public: public:
@@ -57,8 +57,8 @@ public:
void* GetObjAddr() { return (void*)this; } void* GetObjAddr() { return (void*)this; }
}; };
DelayedRefSingletonDeclearTest::DelayedRefSingletonDeclearTest(){}; DelayedRefSingletonDeclearTest::DelayedRefSingletonDeclearTest() {};
DelayedRefSingletonDeclearTest::~DelayedRefSingletonDeclearTest(){}; DelayedRefSingletonDeclearTest::~DelayedRefSingletonDeclearTest() {};
class DelayedRefSingletonTest: public DelayedRefSingleton<DelayedRefSingletonTest> { class DelayedRefSingletonTest: public DelayedRefSingleton<DelayedRefSingletonTest> {
public: public:
@@ -120,13 +120,13 @@ HWTEST_F(UtilsThreadPoolTest, test_05, TestSize.Level0)
EXPECT_EQ((int)pool.GetThreadsNum(), 5); EXPECT_EQ((int)pool.GetThreadsNum(), 5);
EXPECT_EQ((int)pool.GetCurTaskNum(), 0); EXPECT_EQ((int)pool.GetCurTaskNum(), 0);
for ( int i = 0; i < 3; ++i ) for (int i = 0; i < 3; ++i)
{ {
auto task = std::bind(TestFuncAddOneTime, i); auto task = std::bind(TestFuncAddOneTime, i);
pool.AddTask(task); pool.AddTask(task);
} }
for ( int i = 0; i < 2; ++i ) for (int i = 0; i < 2; ++i)
{ {
auto task = std::bind(TestFuncSubOneTime, i); auto task = std::bind(TestFuncSubOneTime, i);
pool.AddTask(task); pool.AddTask(task);
@@ -150,13 +150,13 @@ HWTEST_F(UtilsThreadPoolTest, test_06, TestSize.Level0)
pool.SetMaxTaskNum(10); pool.SetMaxTaskNum(10);
for ( int i = 0; i < 8; ++i ) for (int i = 0; i < 8; ++i)
{ {
auto task = std::bind(TestFuncAddOneTime, i); auto task = std::bind(TestFuncAddOneTime, i);
pool.AddTask(task); pool.AddTask(task);
} }
for ( int i = 0; i < 7; ++i ) for (int i = 0; i < 7; ++i)
{ {
auto task = std::bind(TestFuncSubOneTime, i); auto task = std::bind(TestFuncSubOneTime, i);
pool.AddTask(task); pool.AddTask(task);
@@ -175,7 +175,7 @@ void TestFuncAddWait(int& i)
++g_times; ++g_times;
printf("after func:%s0%d called, :%d\n", __func__, i, g_times); printf("after func:%s0%d called, :%d\n", __func__, i, g_times);
std::unique_lock<std::mutex> lk(g_mutex); std::unique_lock<std::mutex> lk(g_mutex);
g_cv.wait(lk, []{return g_ready;}); g_cv.wait(lk, [] {return g_ready;});
printf("func:%s0%d received ready signal!\n", __func__, i); printf("func:%s0%d received ready signal!\n", __func__, i);
} }
@@ -184,7 +184,7 @@ void TestFuncSubWait(int& i)
--g_times; --g_times;
printf("after func:%s0%d called, :%d\n", __func__, i, g_times); printf("after func:%s0%d called, :%d\n", __func__, i, g_times);
std::unique_lock<std::mutex> lk(g_mutex); std::unique_lock<std::mutex> lk(g_mutex);
g_cv.wait(lk, []{return g_ready;}); g_cv.wait(lk, [] {return g_ready;});
printf("func:%s0%d received ready signal!\n", __func__, i); printf("func:%s0%d received ready signal!\n", __func__, i);
} }
@@ -198,13 +198,13 @@ HWTEST_F(UtilsThreadPoolTest, test_07, TestSize.Level0)
EXPECT_EQ((int)pool.GetThreadsNum(), 5); EXPECT_EQ((int)pool.GetThreadsNum(), 5);
EXPECT_EQ((int)pool.GetCurTaskNum(), 0); EXPECT_EQ((int)pool.GetCurTaskNum(), 0);
for ( int i = 0; i < 3; ++i ) for (int i = 0; i < 3; ++i)
{ {
auto task = std::bind(TestFuncAddWait, i); auto task = std::bind(TestFuncAddWait, i);
pool.AddTask(task); pool.AddTask(task);
} }
for ( int i = 0; i < 2; ++i ) for (int i = 0; i < 2; ++i)
{ {
auto task = std::bind(TestFuncSubWait, i); auto task = std::bind(TestFuncSubWait, i);
pool.AddTask(task); pool.AddTask(task);
@@ -236,13 +236,13 @@ HWTEST_F(UtilsThreadPoolTest, test_08, TestSize.Level0)
pool.SetMaxTaskNum(10); pool.SetMaxTaskNum(10);
// ADD 15 tasks // ADD 15 tasks
for ( int i = 0; i < 8; ++i ) for (int i = 0; i < 8; ++i)
{ {
auto task = std::bind(TestFuncAddWait, i); auto task = std::bind(TestFuncAddWait, i);
pool.AddTask(task); pool.AddTask(task);
} }
for ( int i = 0; i < 7; ++i ) for (int i = 0; i < 7; ++i)
{ {
auto task = std::bind(TestFuncSubWait, i); auto task = std::bind(TestFuncSubWait, i);
pool.AddTask(task); pool.AddTask(task);
+16 -17
View File
@@ -25,9 +25,8 @@ using namespace std;
static int times = 0; static int times = 0;
using ThreadRunFunc = bool (*)(int& data); using ThreadRunFunc = bool (*)(int& data);
class UtilsThreadTest : public testing::Test class UtilsThreadTest : public testing::Test {
{ public:
public :
static void SetUpTestCase(void); static void SetUpTestCase(void);
static void TearDownTestCase(void); static void TearDownTestCase(void);
void SetUp(); void SetUp();
@@ -66,7 +65,7 @@ int GetThreadPriority(const pthread_t& thread)
// scheduling parameters of target thread // scheduling parameters of target thread
ret = pthread_getschedparam (thread, &policy, &param); ret = pthread_getschedparam (thread, &policy, &param);
if (ret != 0){ if (ret != 0) {
printf("pthread_getschedparam failed! thread:%lu, ret:%d\n", thread, ret); printf("pthread_getschedparam failed! thread:%lu, ret:%d\n", thread, ret);
return -1; return -1;
} }
@@ -103,14 +102,14 @@ bool TestRun03(int& data)
constexpr int DEFAULT_PRIO = 0; constexpr int DEFAULT_PRIO = 0;
const std::string& DEFAULT_THREAD_NAME = "default"; const std::string& DEFAULT_THREAD_NAME = "default";
class TestThread : public OHOS::Thread{ class TestThread : public OHOS::Thread {
public: public:
TestThread(const int data, const bool readyToWork, ThreadRunFunc runFunc) TestThread(const int data, const bool readyToWork, ThreadRunFunc runFunc)
: data_(data), priority_(DEFAULT_PRIO), name_(DEFAULT_THREAD_NAME), readyToWork_(readyToWork), runFunc_(runFunc) : data_(data), priority_(DEFAULT_PRIO), name_(DEFAULT_THREAD_NAME), readyToWork_(readyToWork), runFunc_(runFunc)
{}; {};
TestThread() = delete; TestThread() = delete;
~TestThread(){}; ~TestThread() {};
bool ReadyToWork() override; bool ReadyToWork() override;
@@ -158,7 +157,7 @@ HWTEST_F(UtilsThreadTest, testThread001, TestSize.Level0)
pthread_t thread = test->GetThread(); pthread_t thread = test->GetThread();
// pthread_equal return non-zero if equal // pthread_equal return non-zero if equal
EXPECT_EQ(pthread_equal(thread ,-1) != 0, (test->IsRunning() ? false : true)); EXPECT_EQ(pthread_equal(thread, -1) != 0, (test->IsRunning() ? false : true));
// ReadyToWork return false, RUN will not be called! // ReadyToWork return false, RUN will not be called!
EXPECT_EQ(test->priority_, DEFAULT_PRIO); EXPECT_EQ(test->priority_, DEFAULT_PRIO);
@@ -170,7 +169,7 @@ HWTEST_F(UtilsThreadTest, testThread001, TestSize.Level0)
EXPECT_EQ(times, 0); EXPECT_EQ(times, 0);
test->NotifyExitSync(); test->NotifyExitSync();
sleep(1); sleep(1);
EXPECT_EQ(pthread_equal(test->GetThread() ,-1) != 0, (test->IsRunning() ? false : true)); EXPECT_EQ(pthread_equal(test->GetThread(), -1) != 0, (test->IsRunning() ? false : true));
} }
/* /*
@@ -188,7 +187,7 @@ HWTEST_F(UtilsThreadTest, testThread002, TestSize.Level0)
sleep(1); // let the new thread has chance to run sleep(1); // let the new thread has chance to run
// pthread_equal return non-zero if equal, RUN return false,may exit already // pthread_equal return non-zero if equal, RUN return false,may exit already
EXPECT_EQ(pthread_equal(test->GetThread() ,-1) != 0, (test->IsRunning() ? false : true)); EXPECT_EQ(pthread_equal(test->GetThread(), -1) != 0, (test->IsRunning() ? false : true));
// ReadyToWork return true, RUN will be called! // ReadyToWork return true, RUN will be called!
EXPECT_EQ(test->priority_, THREAD_PROI_LOW); EXPECT_EQ(test->priority_, THREAD_PROI_LOW);
@@ -198,7 +197,7 @@ HWTEST_F(UtilsThreadTest, testThread002, TestSize.Level0)
EXPECT_EQ(times, 0); EXPECT_EQ(times, 0);
test->NotifyExitSync(); test->NotifyExitSync();
sleep(1); sleep(1);
EXPECT_EQ(pthread_equal(test->GetThread() ,-1) != 0, (test->IsRunning() ? false : true)); EXPECT_EQ(pthread_equal(test->GetThread(), -1) != 0, (test->IsRunning() ? false : true));
} }
/* /*
@@ -225,7 +224,7 @@ HWTEST_F(UtilsThreadTest, testThread003, TestSize.Level0)
EXPECT_EQ(times, 0); EXPECT_EQ(times, 0);
test->NotifyExitSync(); test->NotifyExitSync();
sleep(1); sleep(1);
EXPECT_EQ(pthread_equal(test->GetThread() ,-1) != 0, (test->IsRunning() ? false : true)); EXPECT_EQ(pthread_equal(test->GetThread(), -1) != 0, (test->IsRunning() ? false : true));
} }
/* /*
@@ -243,7 +242,7 @@ HWTEST_F(UtilsThreadTest, testThread004, TestSize.Level0)
sleep(1); // let the new thread has chance to run sleep(1); // let the new thread has chance to run
// pthread_equal return non-zero if equal, RUN return false,may exit already // pthread_equal return non-zero if equal, RUN return false,may exit already
EXPECT_EQ(pthread_equal(test->GetThread() ,-1) != 0, (test->IsRunning() ? false : true)); EXPECT_EQ(pthread_equal(test->GetThread(), -1) != 0, (test->IsRunning() ? false : true));
// ReadyToWork return true, RUN will be called! // ReadyToWork return true, RUN will be called!
EXPECT_EQ(test->priority_, THREAD_PROI_LOW); EXPECT_EQ(test->priority_, THREAD_PROI_LOW);
@@ -253,7 +252,7 @@ HWTEST_F(UtilsThreadTest, testThread004, TestSize.Level0)
EXPECT_EQ(times, 0); EXPECT_EQ(times, 0);
test->NotifyExitSync(); test->NotifyExitSync();
sleep(1); sleep(1);
EXPECT_EQ(pthread_equal(test->GetThread() ,-1) != 0, (test->IsRunning() ? false : true)); EXPECT_EQ(pthread_equal(test->GetThread(), -1) != 0, (test->IsRunning() ? false : true));
} }
/* /*
@@ -280,7 +279,7 @@ HWTEST_F(UtilsThreadTest, testThread005, TestSize.Level0)
EXPECT_EQ(times, 0); EXPECT_EQ(times, 0);
test->NotifyExitSync(); test->NotifyExitSync();
sleep(1); sleep(1);
EXPECT_EQ(pthread_equal(test->GetThread() ,-1) != 0, (test->IsRunning() ? false : true)); EXPECT_EQ(pthread_equal(test->GetThread(), -1) != 0, (test->IsRunning() ? false : true));
} }
/* /*
@@ -298,7 +297,7 @@ HWTEST_F(UtilsThreadTest, testThread006, TestSize.Level0)
sleep(1); // let the new thread has chance to run sleep(1); // let the new thread has chance to run
// pthread_equal return non-zero if equal, RUN return false,may exit already // pthread_equal return non-zero if equal, RUN return false,may exit already
EXPECT_EQ(pthread_equal(test->GetThread() ,-1) != 0, (test->IsRunning() ? false : true)); EXPECT_EQ(pthread_equal(test->GetThread(), -1) != 0, (test->IsRunning() ? false : true));
// ReadyToWork return true, RUN will be called! // ReadyToWork return true, RUN will be called!
EXPECT_EQ(test->priority_, THREAD_PROI_LOW); EXPECT_EQ(test->priority_, THREAD_PROI_LOW);
@@ -308,11 +307,11 @@ HWTEST_F(UtilsThreadTest, testThread006, TestSize.Level0)
EXPECT_EQ(times, 0); EXPECT_EQ(times, 0);
times = 100; times = 100;
EXPECT_GT(test->data_, 10); EXPECT_GT(test->data_, 10);
sleep(1); // let the new thread has chance to run sleep(1); // let the new thread has chance to run
// times > 10, TestRun03 return false, thread exit // times > 10, TestRun03 return false, thread exit
EXPECT_EQ(pthread_equal(test->GetThread() ,-1) != 0, (test->IsRunning() ? false : true)); EXPECT_EQ(pthread_equal(test->GetThread(), -1) != 0, (test->IsRunning() ? false : true));
} }
@@ -145,7 +145,7 @@ HWTEST_F(UtilsTimerTest, testTimer004, TestSize.Level0)
class A { class A {
public: public:
explicit A(int data) : data_(data), timer_("ATimer"){} explicit A(int data) : data_(data), timer_("ATimer") {}
~A() = default; ~A() = default;
bool Init(); bool Init();
bool StartTimer(int milliseconds, bool once); bool StartTimer(int milliseconds, bool once);