From 4e03adc2e7ddaa9c61ded36ec87668c901d43867 Mon Sep 17 00:00:00 2001 From: Mounir IDRASSI Date: Sun, 8 Feb 2015 23:24:23 +0100 Subject: Static Code Analysis: Add more checks. Avoid unhandled ATL exceptions by checking memory allocation. Avoid throwing exception in File constructor and simplify code. --- src/Common/BootEncryption.h | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'src/Common/BootEncryption.h') diff --git a/src/Common/BootEncryption.h b/src/Common/BootEncryption.h index ccd68bca..3665a9bc 100644 --- a/src/Common/BootEncryption.h +++ b/src/Common/BootEncryption.h @@ -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 () {} }; -- cgit v1.2.3