|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [PATCH 1/5] xenagent: Use new (std::nothrow) where the result is checked for NULL
Plain operator new throws std::bad_alloc instead of returning NULL, so
the NULL checks after these allocations were dead code. Use the nothrow
form so that the existing failure paths are taken on allocation failure.
Assisted-By: Claude:Claude-Opus-5.5
Signed-off-by: Césaire Mounah <cesaire.mounah@xxxxxxxxxx>
---
src/xenagent/convdevice.cpp | 3 ++-
src/xenagent/devicelist.cpp | 3 ++-
src/xenagent/xenifacedevice.cpp | 7 ++++---
3 files changed, 8 insertions(+), 5 deletions(-)
diff --git a/src/xenagent/convdevice.cpp b/src/xenagent/convdevice.cpp
index 5a25be1..b77fe5b 100644
--- a/src/xenagent/convdevice.cpp
+++ b/src/xenagent/convdevice.cpp
@@ -34,6 +34,7 @@
#include <stdio.h>
#include <powrprof.h>
#include <winuser.h>
+#include <new>
#include "service.h"
#include "convdevice.h"
@@ -154,7 +155,7 @@ CConvDeviceList::CConvDeviceList(CXenAgent* agent) :
CDeviceList(GUID_GPIOBUTTON
/*virtual*/ CDevice* CConvDeviceList::Create(const wchar_t* path)
{
- return new CConvDevice(path);
+ return new (std::nothrow) CConvDevice(path);
}
/*virtual*/ void CConvDeviceList::OnDeviceAdded(CDevice* dev)
diff --git a/src/xenagent/devicelist.cpp b/src/xenagent/devicelist.cpp
index d6af5d4..8bf9b2b 100644
--- a/src/xenagent/devicelist.cpp
+++ b/src/xenagent/devicelist.cpp
@@ -31,6 +31,7 @@
#include <windows.h>
#include <string>
+#include <new>
#include <setupapi.h>
#pragma comment (lib , "setupapi.lib" )
@@ -247,7 +248,7 @@ void CDeviceList::EnumerateDevices()
0,
&len,
NULL);
- detail = (PSP_DEVICE_INTERFACE_DETAIL_DATA)new BYTE[len];
+ detail = (PSP_DEVICE_INTERFACE_DETAIL_DATA)new (std::nothrow)
BYTE[len];
if (detail == NULL)
continue;
detail->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA);
diff --git a/src/xenagent/xenifacedevice.cpp b/src/xenagent/xenifacedevice.cpp
index f81a838..763abf0 100644
--- a/src/xenagent/xenifacedevice.cpp
+++ b/src/xenagent/xenifacedevice.cpp
@@ -33,6 +33,7 @@
#include <windows.h>
#include <winioctl.h>
#include <powrprof.h>
+#include <new>
#include "service.h"
#include "xenifacedevice.h"
@@ -65,7 +66,7 @@ bool CXenIfaceDevice::StoreRead(const std::string& path,
std::string& value)
NULL, 0,
&bytes);
- buffer = new char[(size_t)bytes + 1];
+ buffer = new (std::nothrow) char[(size_t)bytes + 1];
if (buffer == NULL)
return false;
@@ -85,7 +86,7 @@ bool CXenIfaceDevice::StoreWrite(const std::string& path,
const std::string& val
{
bool result;
size_t length = path.length() + 1 + value.length() + 1 + 1;
- char* buffer = new char[length];
+ char* buffer = new (std::nothrow) char[length];
if (buffer == NULL)
return false;
@@ -202,7 +203,7 @@ CXenIfaceDeviceList::CXenIfaceDeviceList(CXenAgent* agent)
: CDeviceList(GUID_IN
/*virtual*/ CDevice* CXenIfaceDeviceList::Create(const wchar_t* path)
{
- return new CXenIfaceDevice(path);
+ return new (std::nothrow) CXenIfaceDevice(path);
}
/*virtual*/ void CXenIfaceDeviceList::OnDeviceAdded(CDevice* dev)
--
2.55.0.windows.5
--
Césaire Mounah | Vates Windows Guest Tools Engineer
XCP-ng & Xen Orchestra - Vates solutions
web: https://vates.tech
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |