1
0
mirror of https://github.com/veracrypt/VeraCrypt.git synced 2025-11-11 19:08:26 -06:00

Static Code Analysis: Add more checks. Avoid unhandled ATL exceptions by checking memory allocation. Avoid throwing exception in File constructor and simplify code.

This commit is contained in:
Mounir IDRASSI
2015-02-08 23:24:23 +01:00
parent d1a3316e44
commit 4e03adc2e7
3 changed files with 184 additions and 74 deletions

View File

@@ -22,10 +22,11 @@ namespace VeraCrypt
class File
{
public:
File () : Elevated (false), FileOpen (false), FilePointerPosition(0), Handle(NULL), IsDevice(false) { }
File (string path, bool readOnly = false, bool create = false);
~File () { Close(); }
File () : Elevated (false), FileOpen (false), FilePointerPosition(0), Handle(INVALID_HANDLE_VALUE), IsDevice(false), LastError(0) { }
File (string path,bool readOnly = false, bool create = false);
virtual ~File () { Close(); }
void CheckOpened () { if (!FileOpen) { SetLastError (LastError); throw SystemException ();} }
void Close ();
DWORD Read (byte *buffer, DWORD size);
void Write (byte *buffer, DWORD size);
@@ -38,13 +39,15 @@ namespace VeraCrypt
HANDLE Handle;
bool IsDevice;
string Path;
DWORD LastError;
};
class Device : public File
{
public:
Device (string path, bool readOnly = false);
Device (string path,bool readOnly = false);
virtual ~Device () {}
};