aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2007-04-17 07:47:57 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2007-04-17 07:47:57 +0000
commitd099cef48cd25a65f34bb48506c8ee75f335cea8 (patch)
tree84c60e60b0e51d5139d52850ea3513d81c4cbd3a
parent69bdc6c3128006dbf2ce08ca49c63b0ddc8f842d (diff)
downloadpaludis-d099cef48cd25a65f34bb48506c8ee75f335cea8.tar.gz
paludis-d099cef48cd25a65f34bb48506c8ee75f335cea8.tar.xz
Detect overflow errors when destringifying.
-rw-r--r--paludis/util/destringify.cc3
-rw-r--r--paludis/util/destringify.hh2
-rw-r--r--paludis/util/destringify_TEST.cc2
3 files changed, 5 insertions, 2 deletions
diff --git a/paludis/util/destringify.cc b/paludis/util/destringify.cc
index f601261..652d10a 100644
--- a/paludis/util/destringify.cc
+++ b/paludis/util/destringify.cc
@@ -29,6 +29,7 @@
using namespace paludis;
DestringifyError::DestringifyError(const std::string & str) throw () :
- Exception("Couldn't destringify '" + str + "'." )
+ Exception("Couldn't destringify '" + str + "'")
{
}
+
diff --git a/paludis/util/destringify.hh b/paludis/util/destringify.hh
index 92db3d5..0f74f11 100644
--- a/paludis/util/destringify.hh
+++ b/paludis/util/destringify.hh
@@ -74,7 +74,7 @@ namespace paludis
std::istringstream ss(s);
Type_ t;
ss >> t;
- if (!ss.eof() || ss.bad())
+ if (! ss.eof() || ss.fail())
throw Exception_(s);
return t;
}
diff --git a/paludis/util/destringify_TEST.cc b/paludis/util/destringify_TEST.cc
index 6c49454..8f01173 100644
--- a/paludis/util/destringify_TEST.cc
+++ b/paludis/util/destringify_TEST.cc
@@ -48,6 +48,8 @@ namespace test_cases
TEST_CHECK_EQUAL(destringify<int>("-99"), -99);
TEST_CHECK_EQUAL(destringify<int>(" 12345"), 12345);
TEST_CHECK_THROWS(destringify<int>(""), DestringifyError);
+ TEST_CHECK_THROWS(destringify<int>("x"), DestringifyError);
+ TEST_CHECK_THROWS(destringify<int>("10000000000000000000000000000000000000000000000"), DestringifyError);
}
} test_case_destringify_int;