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

!256 Codex alarm modification

Merge pull request !256 from 周礼亭/master
......@@ -85,6 +85,6 @@ IPCFileDescriptor *IPCFileDescriptor::Unmarshalling(Parcel &parcel)
return nullptr;
}
return new IPCFileDescriptor(fd);
return new (std::nothrow) IPCFileDescriptor(fd);
}
} // namespace OHOS
......@@ -522,7 +522,11 @@ bool IPCObjectProxy::AddDbinderDeathRecipient()
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)) {
ZLOGW(LABEL, "%s: already attach new callback stub", __func__);
return false;
......
......@@ -58,7 +58,11 @@ IPCProcessSkeleton *IPCProcessSkeleton::GetCurrent()
if (instance_ == nullptr) {
std::lock_guard<std::mutex> lockGuard(procMutex_);
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)) {
temp->SpawnThread(IPCWorkThread::SPAWN_ACTIVE);
}
......@@ -176,9 +180,12 @@ bool IPCProcessSkeleton::SetMaxWorkThread(int maxThreadNum)
}
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);
IRemoteInvoker *invoker = IPCThreadSkeleton::GetRemoteInvoker(IRemoteObject::IF_PROT_DEFAULT);
if (invoker != nullptr) {
......
......@@ -27,6 +27,7 @@ namespace IPC_SINGLE {
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_LOGE(fmt, args...) (void)OHOS::HiviewDFX::HiLog::Error(LOG_LABEL, "%{public}d: " fmt, __LINE__, ##args)
IPCWorkThreadPool::IPCWorkThreadPool(int maxThreadNum)
: threadSequence_(0),
......@@ -60,7 +61,12 @@ bool IPCWorkThreadPool::SpawnThread(int policy, int proto)
DBINDER_LOGI("SpawnThread Name= %{public}s", threadName.c_str());
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;
if (proto == IRemoteObject::IF_PROT_DEFAULT) {
idleThreadNum_--;
......
......@@ -57,7 +57,7 @@ IPCThreadSkeleton *IPCThreadSkeleton::GetCurrent()
if (curTLS != nullptr) {
current = reinterpret_cast<IPCThreadSkeleton *>(curTLS);
} else {
current = new IPCThreadSkeleton();
current = new (std::nothrow) IPCThreadSkeleton();
}
return current;
......
......@@ -37,14 +37,11 @@ namespace OHOS {
#define TITLE __PRETTY_FUNCTION__
#endif
#ifndef CONFIG_IPC_SINGLE
static constexpr OHOS::HiviewDFX::HiLogLabel LOG_LABEL = { LOG_CORE, LOG_ID_RPC, "MessageParcel" };
#define DBINDER_LOGE(fmt, args...) \
(void)OHOS::HiviewDFX::HiLog::Error(LOG_LABEL, "%{public}s %{public}d: " fmt, TITLE, __LINE__, ##args)
#define DBINDER_LOGI(fmt, args...) \
(void)OHOS::HiviewDFX::HiLog::Info(LOG_LABEL, "%{public}s %{public}d: " fmt, TITLE, __LINE__, ##args)
#endif
MessageParcel::MessageParcel()
: Parcel(),
......@@ -118,7 +115,11 @@ bool MessageParcel::WriteDBinderProxy(const sptr<IRemoteObject> &object, uint32_
sptr<DBinderCallbackStub> fakeStub = current->QueryDBinderCallbackStub(object);
if (fakeStub == nullptr) {
// 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)) {
DBINDER_LOGE("save callback of fake stub failed");
return false;
......@@ -184,7 +185,11 @@ bool MessageParcel::WriteFileDescriptor(int fd)
if (dupFd < 0) {
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);
}
......@@ -415,6 +420,6 @@ sptr<Ashmem> MessageParcel::ReadAshmem()
::close(fd);
return nullptr;
}
return new Ashmem(fd, size);
return new (std::nothrow) Ashmem(fd, size);
}
} // namespace OHOS
......@@ -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");
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)) {
DBINDER_BASE_LOGE("SetAllocator failed");
delete allocator;
......@@ -847,7 +851,11 @@ template <class T> void DBinderBaseInvoker<T>::ProcessTransaction(dbinder_transa
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)) {
DBINDER_BASE_LOGE("SetAllocator failed");
delete allocator;
......
......@@ -56,7 +56,14 @@ private:
template <typename T> InvokerDelegator<T>::InvokerDelegator(int 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()
......
......@@ -154,7 +154,11 @@ BinderConnector *BinderConnector::GetInstance()
if (instance_ == nullptr) {
std::lock_guard<std::mutex> lockGuard(skeletonMutex);
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()) {
delete temp;
temp = nullptr;
......
......@@ -411,7 +411,12 @@ void BinderInvoker::OnReleaseObject(uint32_t cmd)
void BinderInvoker::OnTransaction(const uint8_t *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);
if (tr->offsets_size > 0) {
data->InjectOffsets(tr->data.ptr.offsets, tr->offsets_size / sizeof(binder_size_t));
......@@ -532,7 +537,11 @@ int BinderInvoker::HandleReply(MessageParcel *reply)
}
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)) {
ZLOGI(LABEL, "SetAllocator failed");
delete allocator;
......
......@@ -49,7 +49,7 @@ void IPCFileDescOpsTest::TearDownTestCase() {}
HWTEST_F(IPCFileDescOpsTest, fd_parcelable_001, TestSize.Level1)
{
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) {
ZLOGI(LABEL, "%s(%d):open failed.", __func__, __LINE__);
......
......@@ -134,7 +134,7 @@ int TestService::TestGetFileDescriptor()
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);
if (testFd_ == INVALID_FD) {
......
......@@ -153,7 +153,7 @@ int TestServiceProxy::TestStringTransaction(const std::string &data)
void TestServiceProxy::TestDumpService()
{
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);
if (fd != INVALID_FD) {
ZLOGI(LABEL, "Start Dump Service");
......@@ -166,7 +166,7 @@ void TestServiceProxy::TestDumpService()
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);
if (fd == INVALID_FD) {
return;
......
......@@ -348,7 +348,7 @@ HWTEST_F(IPCNativeFrameworkTest, function_test_008, TestSize.Level1)
ASSERT_TRUE(object != nullptr);
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);
ASSERT_TRUE(fd > 0);
......
......@@ -132,11 +132,11 @@ pid_t StartExecutable(std::string name, std::string args)
return pid;
}
std::string cmd1 = "chmod +x /data/test/" + name;
std::string cmd1 = "chmod +x /data/" + name;
int res = system(cmd1.c_str());
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());
DBINDER_LOGI("%{public}s res = %{public}d", cmd2.c_str(), res);
......
......@@ -15,14 +15,14 @@
<configuration ver="2.0">
<target name="DbinderTest">
<preparer>
<option name="push" value="communication/ipc/dbinder_test -> /data/test" src="out" />
<option name="push" value="communication/ipc/dbinder_send -> /data/test" src="out" />
<option name="push" value="communication/ipc/dbinder_test -> /data" src="out" />
<option name="push" value="communication/ipc/dbinder_send -> /data" src="out" />
</preparer>
</target>
<target name="DbinderTestAgent">
<preparer>
<option name="push" value="communication/ipc/dbinder_test -> /data/test" src="out" />
<option name="push" value="communication/ipc/dbinder_send -> /data/test" src="out" />
<option name="push" value="communication/ipc/dbinder_test -> /data" src="out" />
<option name="push" value="communication/ipc/dbinder_send -> /data" src="out" />
</preparer>
</target>
</configuration>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册