From 9913af3a8ed61333cafd0e611f214f7c86652423 Mon Sep 17 00:00:00 2001 From: Mounir IDRASSI Date: Wed, 24 Jun 2015 14:14:34 +0200 Subject: Linux/MacOSX: first dynamic mode implementation --- src/Platform/StringConverter.cpp | 48 ++++++++++++++++++++++++++++++++++++++++ src/Platform/StringConverter.h | 8 +++++-- 2 files changed, 54 insertions(+), 2 deletions(-) (limited to 'src/Platform') diff --git a/src/Platform/StringConverter.cpp b/src/Platform/StringConverter.cpp index cbd89e1f..c7ecc143 100644 --- a/src/Platform/StringConverter.cpp +++ b/src/Platform/StringConverter.cpp @@ -259,6 +259,30 @@ namespace VeraCrypt if (ss.fail() || n == 0xffffFFFFU) throw ParameterIncorrect (SRC_POS); + return n; + } + + int32 StringConverter::ToInt32 (const string &str) + { + int32 n; + stringstream ss (str); + + ss >> n; + if (ss.fail() || n == 0x7fffFFFF || n == -0x7fffFFFF) + throw ParameterIncorrect (SRC_POS); + + return n; + } + + int32 StringConverter::ToInt32 (const wstring &str) + { + int32 n; + wstringstream ss (str); + + ss >> n; + if (ss.fail() || n == 0x7fffFFFF || n == -0x7fffFFFF) + throw ParameterIncorrect (SRC_POS); + return n; } @@ -283,6 +307,30 @@ namespace VeraCrypt if (ss.fail() || n == 0xffffFFFFffffFFFFULL) throw ParameterIncorrect (SRC_POS); + return n; + } + + int64 StringConverter::ToInt64 (const string &str) + { + int64 n; + stringstream ss (str); + + ss >> n; + if (ss.fail() || n == 0x7fffFFFFffffFFFFLL || n == -0x7fffFFFFffffFFFFLL) + throw ParameterIncorrect (SRC_POS); + + return n; + } + + int64 StringConverter::ToInt64 (const wstring &str) + { + int64 n; + wstringstream ss (str); + + ss >> n; + if (ss.fail() || n == 0x7fffFFFFffffFFFFLL || n == -0x7fffFFFFffffFFFFLL) + throw ParameterIncorrect (SRC_POS); + return n; } diff --git a/src/Platform/StringConverter.h b/src/Platform/StringConverter.h index 9a9e098f..7b68ff4d 100644 --- a/src/Platform/StringConverter.h +++ b/src/Platform/StringConverter.h @@ -32,9 +32,13 @@ namespace VeraCrypt static wstring ToExceptionString (const exception &ex); static string ToLower (const string &str); static uint32 ToUInt32 (const string &str); - static uint32 ToUInt32 (const wstring &str); + static uint32 ToUInt32 (const wstring &str); + static int32 ToInt32 (const string &str); + static int32 ToInt32 (const wstring &str); static uint64 ToUInt64 (const string &str); - static uint64 ToUInt64 (const wstring &str); + static uint64 ToUInt64 (const wstring &str); + static int64 ToInt64 (const string &str); + static int64 ToInt64 (const wstring &str); static string ToSingle (double number) { return ToSingle (FromNumber (number)); } static string ToSingle (int32 number) { return ToSingle (FromNumber (number)); } static string ToSingle (uint32 number) { return ToSingle (FromNumber (number)); } -- cgit v1.2.3