未验证 提交 56433846 编写于 作者: O openharmony_ci 提交者: Gitee

!256 Codex alarm modification

Merge pull request !256 from 周礼亭/master
...@@ -85,6 +85,6 @@ IPCFileDescriptor *IPCFileDescriptor::Unmarshalling(Parcel &parcel) ...@@ -85,6 +85,6 @@ IPCFileDescriptor *IPCFileDescriptor::Unmarshalling(Parcel &parcel)
return nullptr; return nullptr;
} }
return new IPCFileDescriptor(fd); return new (std::nothrow) IPCFileDescriptor(fd);
} }
} // namespace OHOS } // namespace OHOS
...@@ -522,7 +522,11 @@ bool IPCObjectProxy::AddDbinderDeathRecipient() ...@@ -522,7 +522,11 @@ bool IPCObjectProxy::AddDbinderDeathRecipient()
return true; return true;
} }
sptr<IPCObjectStub> callbackStub = new IPCObjectStub(descriptor_); sptr<IPCObjectStub> callbackStub = new (std::nothrow) IPCObjectStub(descriptor_);
if (callbackStub == nullptr) {
ZLOGE(LABEL, "create IPCObjectStub object failed");
return false;
}
if (!current->AttachCallbackStub(this, callbackStub)) { if (!current->AttachCallbackStub(this, callbackStub)) {
ZLOGW(LABEL, "%s: already attach new callback stub", __func__); ZLOGW(LABEL, "%s: already attach new callback stub", __func__);
return false; return false;
......
...@@ -58,7 +58,11 @@ IPCProcessSkeleton *IPCProcessSkeleton::GetCurrent() ...@@ -58,7 +58,11 @@ IPCProcessSkeleton *IPCProcessSkeleton::GetCurrent()
if (instance_ == nullptr) { if (instance_ == nullptr) {
std::lock_guard<std::mutex> lockGuard(procMutex_); std::lock_guard<std::mutex> lockGuard(procMutex_);
if (instance_ == nullptr) { if (instance_ == nullptr) {
IPCProcessSkeleton *temp = new IPCProcessSkeleton(); IPCProcessSkeleton *temp = new (std::nothrow) IPCProcessSkeleton();
if (temp == nullptr) {
DBINDER_LOGE("create IPCProcessSkeleton object failed");
return nullptr;
}
if (temp->SetMaxWorkThread(DEFAULT_WORK_THREAD_NUM)) { if (temp->SetMaxWorkThread(DEFAULT_WORK_THREAD_NUM)) {
temp->SpawnThread(IPCWorkThread::SPAWN_ACTIVE); temp->SpawnThread(IPCWorkThread::SPAWN_ACTIVE);
} }
...@@ -176,9 +180,12 @@ bool IPCProcessSkeleton::SetMaxWorkThread(int maxThreadNum) ...@@ -176,9 +180,12 @@ bool IPCProcessSkeleton::SetMaxWorkThread(int maxThreadNum)
} }
if (threadPool_ == nullptr) { if (threadPool_ == nullptr) {
threadPool_ = new IPCWorkThreadPool(maxThreadNum); threadPool_ = new (std::nothrow) IPCWorkThreadPool(maxThreadNum);
if (threadPool_ == nullptr) {
DBINDER_LOGE("create IPCWorkThreadPool object failed");
return false;
}
} }
threadPool_->UpdateMaxThreadNum(maxThreadNum); threadPool_->UpdateMaxThreadNum(maxThreadNum);
IRemoteInvoker *invoker = IPCThreadSkeleton::GetRemoteInvoker(IRemoteObject::IF_PROT_DEFAULT); IRemoteInvoker *invoker = IPCThreadSkeleton::GetRemoteInvoker(IRemoteObject::IF_PROT_DEFAULT);
if (invoker != nullptr) { if (invoker != nullptr) {
......
...@@ -27,6 +27,7 @@ namespace IPC_SINGLE { ...@@ -27,6 +27,7 @@ namespace IPC_SINGLE {
static constexpr OHOS::HiviewDFX::HiLogLabel LOG_LABEL = { LOG_CORE, LOG_ID_IPC, "IPCWorkThreadPool" }; static constexpr OHOS::HiviewDFX::HiLogLabel LOG_LABEL = { LOG_CORE, LOG_ID_IPC, "IPCWorkThreadPool" };
#define DBINDER_LOGI(fmt, args...) (void)OHOS::HiviewDFX::HiLog::Info(LOG_LABEL, "%{public}d: " fmt, __LINE__, ##args) #define DBINDER_LOGI(fmt, args...) (void)OHOS::HiviewDFX::HiLog::Info(LOG_LABEL, "%{public}d: " fmt, __LINE__, ##args)
#define DBINDER_LOGE(fmt, args...) (void)OHOS::HiviewDFX::HiLog::Error(LOG_LABEL, "%{public}d: " fmt, __LINE__, ##args)
IPCWorkThreadPool::IPCWorkThreadPool(int maxThreadNum) IPCWorkThreadPool::IPCWorkThreadPool(int maxThreadNum)
: threadSequence_(0), : threadSequence_(0),
...@@ -60,7 +61,12 @@ bool IPCWorkThreadPool::SpawnThread(int policy, int proto) ...@@ -60,7 +61,12 @@ bool IPCWorkThreadPool::SpawnThread(int policy, int proto)
DBINDER_LOGI("SpawnThread Name= %{public}s", threadName.c_str()); DBINDER_LOGI("SpawnThread Name= %{public}s", threadName.c_str());
if (threads_.find(threadName) == threads_.end()) { if (threads_.find(threadName) == threads_.end()) {
sptr<IPCWorkThread> newThread = sptr<IPCWorkThread>(new IPCWorkThread(threadName)); auto ipcThread = new (std::nothrow) IPCWorkThread(threadName);
if (ipcThread == nullptr) {
DBINDER_LOGE("create IPCWorkThread object failed");
return false;
}
sptr<IPCWorkThread> newThread = sptr<IPCWorkThread>(ipcThread);
threads_[threadName] = newThread; threads_[threadName] = newThread;
if (proto == IRemoteObject::IF_PROT_DEFAULT) { if (proto == IRemoteObject::IF_PROT_DEFAULT) {
idleThreadNum_--; idleThreadNum_--;
......
...@@ -57,7 +57,7 @@ IPCThreadSkeleton *IPCThreadSkeleton::GetCurrent() ...@@ -57,7 +57,7 @@ IPCThreadSkeleton *IPCThreadSkeleton::GetCurrent()
if (curTLS != nullptr) { if (curTLS != nullptr) {
current = reinterpret_cast<IPCThreadSkeleton *>(curTLS); current = reinterpret_cast<IPCThreadSkeleton *>(curTLS);
} else { } else {
current = new IPCThreadSkeleton(); current = new (std::nothrow) IPCThreadSkeleton();
} }
return current; return current;
......
...@@ -37,14 +37,11 @@ namespace OHOS { ...@@ -37,14 +37,11 @@ namespace OHOS {
#define TITLE __PRETTY_FUNCTION__ #define TITLE __PRETTY_FUNCTION__
#endif #endif
#ifndef CONFIG_IPC_SINGLE
static constexpr OHOS::HiviewDFX::HiLogLabel LOG_LABEL = { LOG_CORE, LOG_ID_RPC, "MessageParcel" }; static constexpr OHOS::HiviewDFX::HiLogLabel LOG_LABEL = { LOG_CORE, LOG_ID_RPC, "MessageParcel" };
#define DBINDER_LOGE(fmt, args...) \ #define DBINDER_LOGE(fmt, args...) \
(void)OHOS::HiviewDFX::HiLog::Error(LOG_LABEL, "%{public}s %{public}d: " fmt, TITLE, __LINE__, ##args) (void)OHOS::HiviewDFX::HiLog::Error(LOG_LABEL, "%{public}s %{public}d: " fmt, TITLE, __LINE__, ##args)
#define DBINDER_LOGI(fmt, args...) \ #define DBINDER_LOGI(fmt, args...) \
(void)OHOS::HiviewDFX::HiLog::Info(LOG_LABEL, "%{public}s %{public}d: " fmt, TITLE, __LINE__, ##args) (void)OHOS::HiviewDFX::HiLog::Info(LOG_LABEL, "%{public}s %{public}d: " fmt, TITLE, __LINE__, ##args)
#endif
MessageParcel::MessageParcel() MessageParcel::MessageParcel()
: Parcel(), : Parcel(),
...@@ -118,7 +115,11 @@ bool MessageParcel::WriteDBinderProxy(const sptr<IRemoteObject> &object, uint32_ ...@@ -118,7 +115,11 @@ bool MessageParcel::WriteDBinderProxy(const sptr<IRemoteObject> &object, uint32_
sptr<DBinderCallbackStub> fakeStub = current->QueryDBinderCallbackStub(object); sptr<DBinderCallbackStub> fakeStub = current->QueryDBinderCallbackStub(object);
if (fakeStub == nullptr) { if (fakeStub == nullptr) {
// note that cannot use this proxy's descriptor // note that cannot use this proxy's descriptor
fakeStub = new DBinderCallbackStub(peerName, peerId, localId, stubIndex, handle, feature); fakeStub = new (std::nothrow) DBinderCallbackStub(peerName, peerId, localId, stubIndex, handle, feature);
if (fakeStub == nullptr) {
DBINDER_LOGE("create DBinderCallbackStub object failed");
return false;
}
if (!current->AttachDBinderCallbackStub(object, fakeStub)) { if (!current->AttachDBinderCallbackStub(object, fakeStub)) {
DBINDER_LOGE("save callback of fake stub failed"); DBINDER_LOGE("save callback of fake stub failed");
return false; return false;
...@@ -184,7 +185,11 @@ bool MessageParcel::WriteFileDescriptor(int fd) ...@@ -184,7 +185,11 @@ bool MessageParcel::WriteFileDescriptor(int fd)
if (dupFd < 0) { if (dupFd < 0) {
return false; return false;
} }
sptr<IPCFileDescriptor> descriptor = new IPCFileDescriptor(dupFd); sptr<IPCFileDescriptor> descriptor = new (std::nothrow) IPCFileDescriptor(dupFd);
if (descriptor == nullptr) {
DBINDER_LOGE("create IPCFileDescriptor object failed");
return false;
}
return WriteObject<IPCFileDescriptor>(descriptor); return WriteObject<IPCFileDescriptor>(descriptor);
} }
...@@ -415,6 +420,6 @@ sptr<Ashmem> MessageParcel::ReadAshmem() ...@@ -415,6 +420,6 @@ sptr<Ashmem> MessageParcel::ReadAshmem()
::close(fd); ::close(fd);
return nullptr; return nullptr;
} }
return new Ashmem(fd, size); return new (std::nothrow) Ashmem(fd, size);
} }
} // namespace OHOS } // namespace OHOS
...@@ -595,7 +595,11 @@ template <class T> int DBinderBaseInvoker<T>::HandleReply(uint64_t seqNumber, Me ...@@ -595,7 +595,11 @@ template <class T> int DBinderBaseInvoker<T>::HandleReply(uint64_t seqNumber, Me
DBINDER_BASE_LOGE("need reply message, but buffer is nullptr"); DBINDER_BASE_LOGE("need reply message, but buffer is nullptr");
return RPC_BASE_INVOKER_INVALID_REPLY_ERR; return RPC_BASE_INVOKER_INVALID_REPLY_ERR;
} }
auto allocator = new DBinderRecvAllocator(); auto allocator = new (std::nothrow) DBinderRecvAllocator();
if (allocator == nullptr) {
DBINDER_BASE_LOGE("create DBinderRecvAllocator object failed");
return RPC_BASE_INVOKER_INVALID_REPLY_ERR;
}
if (!reply->SetAllocator(allocator)) { if (!reply->SetAllocator(allocator)) {
DBINDER_BASE_LOGE("SetAllocator failed"); DBINDER_BASE_LOGE("SetAllocator failed");
delete allocator; delete allocator;
...@@ -847,7 +851,11 @@ template <class T> void DBinderBaseInvoker<T>::ProcessTransaction(dbinder_transa ...@@ -847,7 +851,11 @@ template <class T> void DBinderBaseInvoker<T>::ProcessTransaction(dbinder_transa
return; return;
} }
auto allocator = new DBinderSendAllocator(); auto allocator = new (std::nothrow) DBinderSendAllocator();
if (allocator == nullptr) {
DBINDER_BASE_LOGE("DBinderSendAllocator Creation failed");
return;
}
if (!data.SetAllocator(allocator)) { if (!data.SetAllocator(allocator)) {
DBINDER_BASE_LOGE("SetAllocator failed"); DBINDER_BASE_LOGE("SetAllocator failed");
delete allocator; delete allocator;
......
...@@ -56,7 +56,14 @@ private: ...@@ -56,7 +56,14 @@ private:
template <typename T> InvokerDelegator<T>::InvokerDelegator(int prot) template <typename T> InvokerDelegator<T>::InvokerDelegator(int prot)
{ {
prot_ = prot; prot_ = prot;
InvokerFactory::Get().Register(prot, []() { return static_cast<IRemoteInvoker *>(new T()); }); auto invokerObject = []() -> IRemoteInvoker * {
auto data = new (std::nothrow) T();
if (data == nullptr) {
return nullptr;
}
return static_cast<IRemoteInvoker *>(data);
};
InvokerFactory::Get().Register(prot, invokerObject);
} }
template <typename T> InvokerDelegator<T>::~InvokerDelegator() template <typename T> InvokerDelegator<T>::~InvokerDelegator()
......
...@@ -154,7 +154,11 @@ BinderConnector *BinderConnector::GetInstance() ...@@ -154,7 +154,11 @@ BinderConnector *BinderConnector::GetInstance()
if (instance_ == nullptr) { if (instance_ == nullptr) {
std::lock_guard<std::mutex> lockGuard(skeletonMutex); std::lock_guard<std::mutex> lockGuard(skeletonMutex);
if (instance_ == nullptr) { if (instance_ == nullptr) {
BinderConnector *temp = new BinderConnector(DRIVER_NAME); auto temp = new (std::nothrow) BinderConnector(DRIVER_NAME);
if (temp == nullptr) {
ZLOGE(LABEL, "create BinderConnector object failed");
return nullptr;
}
if (!temp->OpenDriver()) { if (!temp->OpenDriver()) {
delete temp; delete temp;
temp = nullptr; temp = nullptr;
......
...@@ -411,7 +411,12 @@ void BinderInvoker::OnReleaseObject(uint32_t cmd) ...@@ -411,7 +411,12 @@ void BinderInvoker::OnReleaseObject(uint32_t cmd)
void BinderInvoker::OnTransaction(const uint8_t *buffer) void BinderInvoker::OnTransaction(const uint8_t *buffer)
{ {
const binder_transaction_data *tr = reinterpret_cast<const binder_transaction_data *>(buffer); const binder_transaction_data *tr = reinterpret_cast<const binder_transaction_data *>(buffer);
auto data = std::make_unique<MessageParcel>(new BinderAllocator()); auto binderAllocator = new (std::nothrow) BinderAllocator();
if (binderAllocator == nullptr) {
ZLOGE(LABEL, "BinderAllocator Creation failed");
return;
}
auto data = std::make_unique<MessageParcel>(binderAllocator);
data->ParseFrom(tr->data.ptr.buffer, tr->data_size); data->ParseFrom(tr->data.ptr.buffer, tr->data_size);
if (tr->offsets_size > 0) { if (tr->offsets_size > 0) {
data->InjectOffsets(tr->data.ptr.offsets, tr->offsets_size / sizeof(binder_size_t)); data->InjectOffsets(tr->data.ptr.offsets, tr->offsets_size / sizeof(binder_size_t));
...@@ -532,7 +537,11 @@ int BinderInvoker::HandleReply(MessageParcel *reply) ...@@ -532,7 +537,11 @@ int BinderInvoker::HandleReply(MessageParcel *reply)
} }
if (tr->data_size > 0) { if (tr->data_size > 0) {
auto allocator = new BinderAllocator(); auto allocator = new (std::nothrow) BinderAllocator();
if (allocator == nullptr) {
ZLOGE(LABEL, "create BinderAllocator object failed");
return IPC_INVOKER_INVALID_DATA_ERR;
}
if (!reply->SetAllocator(allocator)) { if (!reply->SetAllocator(allocator)) {
ZLOGI(LABEL, "SetAllocator failed"); ZLOGI(LABEL, "SetAllocator failed");
delete allocator; delete allocator;
......
...@@ -49,7 +49,7 @@ void IPCFileDescOpsTest::TearDownTestCase() {} ...@@ -49,7 +49,7 @@ void IPCFileDescOpsTest::TearDownTestCase() {}
HWTEST_F(IPCFileDescOpsTest, fd_parcelable_001, TestSize.Level1) HWTEST_F(IPCFileDescOpsTest, fd_parcelable_001, TestSize.Level1)
{ {
int testFdNum; int testFdNum;
testFdNum = open("/data/test/fd_unit_test.txt", O_RDWR | O_APPEND | O_CREAT, S_IRWXU | S_IRWXG | S_IRWXO); testFdNum = open("/data/fd_unit_test.txt", O_RDWR | O_APPEND | O_CREAT, S_IRWXU | S_IRWXG | S_IRWXO);
if (testFdNum == -1) { if (testFdNum == -1) {
ZLOGI(LABEL, "%s(%d):open failed.", __func__, __LINE__); ZLOGI(LABEL, "%s(%d):open failed.", __func__, __LINE__);
......
...@@ -134,7 +134,7 @@ int TestService::TestGetFileDescriptor() ...@@ -134,7 +134,7 @@ int TestService::TestGetFileDescriptor()
close(testFd_); close(testFd_);
} }
testFd_ = open("/data/test/test.txt", testFd_ = open("/data/test.txt",
O_RDWR | O_APPEND | O_CREAT, S_IRWXU | S_IRWXG | S_IRWXO); O_RDWR | O_APPEND | O_CREAT, S_IRWXU | S_IRWXG | S_IRWXO);
if (testFd_ == INVALID_FD) { if (testFd_ == INVALID_FD) {
......
...@@ -153,7 +153,7 @@ int TestServiceProxy::TestStringTransaction(const std::string &data) ...@@ -153,7 +153,7 @@ int TestServiceProxy::TestStringTransaction(const std::string &data)
void TestServiceProxy::TestDumpService() void TestServiceProxy::TestDumpService()
{ {
ZLOGI(LABEL, "call StartDumpService"); ZLOGI(LABEL, "call StartDumpService");
int fd = open("/data/test/dump.txt", int fd = open("/data/dump.txt",
O_RDWR | O_APPEND | O_CREAT, S_IRWXU | S_IRWXG | S_IRWXO); O_RDWR | O_APPEND | O_CREAT, S_IRWXU | S_IRWXG | S_IRWXO);
if (fd != INVALID_FD) { if (fd != INVALID_FD) {
ZLOGI(LABEL, "Start Dump Service"); ZLOGI(LABEL, "Start Dump Service");
...@@ -166,7 +166,7 @@ void TestServiceProxy::TestDumpService() ...@@ -166,7 +166,7 @@ void TestServiceProxy::TestDumpService()
void TestServiceProxy::TestAsyncDumpService() void TestServiceProxy::TestAsyncDumpService()
{ {
int fd = open("/data/test/nonblockingDump.txt", int fd = open("/data/nonblockingDump.txt",
O_RDWR | O_APPEND | O_CREAT, S_IRWXU | S_IRWXG | S_IRWXO); O_RDWR | O_APPEND | O_CREAT, S_IRWXU | S_IRWXG | S_IRWXO);
if (fd == INVALID_FD) { if (fd == INVALID_FD) {
return; return;
......
...@@ -348,7 +348,7 @@ HWTEST_F(IPCNativeFrameworkTest, function_test_008, TestSize.Level1) ...@@ -348,7 +348,7 @@ HWTEST_F(IPCNativeFrameworkTest, function_test_008, TestSize.Level1)
ASSERT_TRUE(object != nullptr); ASSERT_TRUE(object != nullptr);
ZLOGI(LABEL, "get test.service OK"); ZLOGI(LABEL, "get test.service OK");
int fd = open("/data/test/dump.txt", int fd = open("/data/dump.txt",
O_RDWR | O_APPEND | O_CREAT, S_IRWXU | S_IRWXG | S_IRWXO); O_RDWR | O_APPEND | O_CREAT, S_IRWXU | S_IRWXG | S_IRWXO);
ASSERT_TRUE(fd > 0); ASSERT_TRUE(fd > 0);
......
...@@ -132,11 +132,11 @@ pid_t StartExecutable(std::string name, std::string args) ...@@ -132,11 +132,11 @@ pid_t StartExecutable(std::string name, std::string args)
return pid; return pid;
} }
std::string cmd1 = "chmod +x /data/test/" + name; std::string cmd1 = "chmod +x /data/" + name;
int res = system(cmd1.c_str()); int res = system(cmd1.c_str());
DBINDER_LOGI("%{public}s res = %d, errno = %{public}d %{public}s", cmd1.c_str(), res, errno, strerror(errno)); DBINDER_LOGI("%{public}s res = %d, errno = %{public}d %{public}s", cmd1.c_str(), res, errno, strerror(errno));
std::string cmd2 = "/data/test/" + name + " " + args + "&"; std::string cmd2 = "/data/" + name + " " + args + "&";
res = system(cmd2.c_str()); res = system(cmd2.c_str());
DBINDER_LOGI("%{public}s res = %{public}d", cmd2.c_str(), res); DBINDER_LOGI("%{public}s res = %{public}d", cmd2.c_str(), res);
......
...@@ -15,14 +15,14 @@ ...@@ -15,14 +15,14 @@
<configuration ver="2.0"> <configuration ver="2.0">
<target name="DbinderTest"> <target name="DbinderTest">
<preparer> <preparer>
<option name="push" value="communication/ipc/dbinder_test -> /data/test" src="out" /> <option name="push" value="communication/ipc/dbinder_test -> /data" src="out" />
<option name="push" value="communication/ipc/dbinder_send -> /data/test" src="out" /> <option name="push" value="communication/ipc/dbinder_send -> /data" src="out" />
</preparer> </preparer>
</target> </target>
<target name="DbinderTestAgent"> <target name="DbinderTestAgent">
<preparer> <preparer>
<option name="push" value="communication/ipc/dbinder_test -> /data/test" src="out" /> <option name="push" value="communication/ipc/dbinder_test -> /data" src="out" />
<option name="push" value="communication/ipc/dbinder_send -> /data/test" src="out" /> <option name="push" value="communication/ipc/dbinder_send -> /data" src="out" />
</preparer> </preparer>
</target> </target>
</configuration> </configuration>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册