summaryrefslogtreecommitdiffstats
path: root/libtests/qutil.cc
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2013-02-26 18:31:00 +0100
committerJay Berkenbilt <ejb@ql.org>2013-03-04 22:45:16 +0100
commit8be827761347b7a0a4ce6e7bdfa6fd4585606b21 (patch)
treedf3f715342a7df15156805d5f21511ad635a11b1 /libtests/qutil.cc
parented19516aa77b632197f47d0ddcd9632678baab98 (diff)
downloadqpdf-8be827761347b7a0a4ce6e7bdfa6fd4585606b21.tar.zst
Rewrite QUtil::int_to_string and QUtil::double_to_string
Make them safer by avoiding any internal limits and replacing sprintf with std::ostringstream.
Diffstat (limited to 'libtests/qutil.cc')
-rw-r--r--libtests/qutil.cc57
1 files changed, 5 insertions, 52 deletions
diff --git a/libtests/qutil.cc b/libtests/qutil.cc
index ad77f3ea..4e8c7362 100644
--- a/libtests/qutil.cc
+++ b/libtests/qutil.cc
@@ -19,58 +19,11 @@ void string_conversion_test()
<< QUtil::int_to_string(16059, -7) << std::endl
<< QUtil::double_to_string(3.14159) << std::endl
<< QUtil::double_to_string(3.14159, 3) << std::endl
- << QUtil::double_to_string(1000.123, -1024) << std::endl;
-
- try
- {
- // int_to_string bounds error
- std::cout << QUtil::int_to_string(1, 50) << std::endl;
- }
- catch (std::logic_error &e)
- {
- std::cout << "exception 1: " << e.what() << std::endl;
- }
-
- try
- {
- // QUtil::int_to_string bounds error
- std::cout << QUtil::int_to_string(1, -50) << std::endl;
- }
- catch (std::logic_error& e)
- {
- std::cout << "exception 2: " << e.what() << std::endl;
- }
-
- try
- {
- // QUtil::int_to_string bounds error
- std::cout << QUtil::int_to_string(-1, 49) << std::endl;
- }
- catch (std::logic_error& e)
- {
- std::cout << "exception 3: " << e.what() << std::endl;
- }
-
-
- try
- {
- // QUtil::double_to_string bounds error
- std::cout << QUtil::double_to_string(3.14159, 1024) << std::endl;
- }
- catch (std::logic_error& e)
- {
- std::cout << "exception 4: " << e.what() << std::endl;
- }
-
- try
- {
- // QUtil::double_to_string bounds error
- std::cout << QUtil::double_to_string(1000.0, 95) << std::endl;
- }
- catch (std::logic_error& e)
- {
- std::cout << "exception 5: " << e.what() << std::endl;
- }
+ << QUtil::double_to_string(1000.123, -1024) << std::endl
+ << QUtil::double_to_string(.1234, 5) << std::endl
+ << QUtil::double_to_string(.0001234, 5) << std::endl
+ << QUtil::double_to_string(.123456, 5) << std::endl
+ << QUtil::double_to_string(.000123456, 5) << std::endl;
std::string embedded_null = "one";
embedded_null += '\0';