UsbDk: simplify CRegText and make it more robust
1. Replace pointer to CWdmMemoryBuffer with inplace object 2. Ensure proper error handling on memory allocation failures Signed-off-by: Pavel Gurvich <pavel@daynix.com> Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
This commit is contained in:
parent
7bfc8c8fb4
commit
0cdabff70d
3 changed files with 8 additions and 15 deletions
|
|
@ -23,8 +23,3 @@
|
|||
|
||||
#include "stdafx.h"
|
||||
#include "MemoryBuffer.h"
|
||||
|
||||
CWdmMemoryBuffer* CWdmMemoryBuffer::GetMemoryBuffer(PVOID Buffer, SIZE_T Size)
|
||||
{
|
||||
return new CWdmMemoryBuffer(Buffer, Size);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -74,8 +74,6 @@ public:
|
|||
~CWdmMemoryBuffer()
|
||||
{ if(m_Ptr != nullptr) { ExFreePool(m_Ptr); } }
|
||||
|
||||
static CWdmMemoryBuffer* GetMemoryBuffer(PVOID Buffer, SIZE_T Size);
|
||||
|
||||
PVOID Ptr() const { return m_Ptr; }
|
||||
SIZE_T Size() const { return m_Size; }
|
||||
|
||||
|
|
|
|||
|
|
@ -43,19 +43,19 @@ public:
|
|||
|
||||
virtual ~CRegText() {}
|
||||
|
||||
iterator begin() const { return static_cast<PWCHAR> (m_Data->Ptr()); }
|
||||
iterator end() const { return reinterpret_cast<PWCHAR>(static_cast<PCHAR>(m_Data->Ptr()) + m_Data->Size()); }
|
||||
bool empty() const { return (m_Data->Size() == 0); }
|
||||
iterator begin() const { return static_cast<PWCHAR> (m_Data.Ptr()); }
|
||||
iterator end() const { return reinterpret_cast<PWCHAR>(static_cast<PCHAR>(m_Data.Ptr()) + m_Data.Size()); }
|
||||
bool empty() const { return (m_Data.Size() == 0); }
|
||||
|
||||
bool Match(PCWSTR String) const;
|
||||
bool MatchPrefix(PCWSTR String) const;
|
||||
void Dump() const;
|
||||
|
||||
CRegText(CWdmMemoryBuffer* Data)
|
||||
: m_Data(Data) {}
|
||||
CRegText(PVOID Buffer, SIZE_T Size)
|
||||
: m_Data(Buffer, Size) {}
|
||||
|
||||
private:
|
||||
CObjHolder<CWdmMemoryBuffer> m_Data;
|
||||
CWdmMemoryBuffer m_Data;
|
||||
SIZE_T m_currPos = 0;
|
||||
};
|
||||
|
||||
|
|
@ -63,7 +63,7 @@ class CRegSz : public CRegText
|
|||
{
|
||||
public:
|
||||
CRegSz(PWCHAR Data)
|
||||
: CRegText(CWdmMemoryBuffer::GetMemoryBuffer(static_cast<PVOID>(Data), GetBufferLength(Data)))
|
||||
: CRegText(static_cast<PVOID>(Data), GetBufferLength(Data))
|
||||
{}
|
||||
static SIZE_T GetBufferLength(PWCHAR Data) { return (Data != nullptr) ? (wcslen(Data) + 1) * sizeof(WCHAR) : 0; }
|
||||
};
|
||||
|
|
@ -72,7 +72,7 @@ class CRegMultiSz : public CRegText
|
|||
{
|
||||
public:
|
||||
CRegMultiSz(PWCHAR Data)
|
||||
: CRegText(CWdmMemoryBuffer::GetMemoryBuffer(static_cast<PVOID>(Data), GetBufferLength(Data)))
|
||||
: CRegText(static_cast<PVOID>(Data), GetBufferLength(Data))
|
||||
{}
|
||||
static SIZE_T GetBufferLength(PWCHAR Data);
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue