VeraCrypt
aboutsummaryrefslogtreecommitdiff
path: root/src/Platform
diff options
context:
space:
mode:
Diffstat (limited to 'src/Platform')
-rw-r--r--src/Platform/StringConverter.cpp48
-rw-r--r--src/Platform/StringConverter.h8
2 files changed, 54 insertions, 2 deletions
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
@@ -260,6 +260,30 @@ namespace VeraCrypt
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;
}
uint64 StringConverter::ToUInt64 (const string &str)
@@ -284,6 +308,30 @@ namespace VeraCrypt
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;
}
string StringConverter::ToUpper (const string &str)
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)); }