BigUnsignedInABase(std::string): Reject digits too big for the base.
authorMatt McCutchen <matt@mattmccutchen.net>
Fri, 27 Mar 2009 00:19:54 +0000 (20:19 -0400)
committerMatt McCutchen <matt@mattmccutchen.net>
Fri, 27 Mar 2009 00:22:06 +0000 (20:22 -0400)
Bug reported by Niakam Kazemi.

BigUnsignedInABase.cc
ChangeLog
testsuite.cc

index c849014..999faaf 100644 (file)
@@ -95,6 +95,9 @@ BigUnsignedInABase::BigUnsignedInABase(const std::string &s, Base base) {
                        blk[digitNum] = theSymbol - 'a' + 10;
                else
                        throw "BigUnsignedInABase(std::string, Base): Bad symbol in input.  Only 0-9, A-Z, a-z are accepted.";
+
+               if (blk[digitNum] >= base)
+                       throw "BigUnsignedInABase::BigUnsignedInABase(const Digit *, Index, Base): A digit is too large for the specified base";
        }
        zapLeadingZeros();
 }
index bf86875..5294223 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -6,6 +6,11 @@ roughly corresponds to the release date of that version in `YYYY.MM.DD[.N]'
 format, where `.N' goes `.2', `.3', etc. if there are multiple versions on the
 same day.  The topmost version listed is the one you have.
 
+Unreleased
+----------
+- BigUnsignedInABase(std::string) Reject digits too big for the base.
+  Bug reported by Niakam Kazemi.
+
 2008.07.20
 ----------
 Dennis Yew pointed out serious problems with ambiguities and unwanted
index 7817e9a..7cb9768 100644 (file)
@@ -311,6 +311,13 @@ TEST(p2); //-15
        TEST(check(num)); //25
 }
 
+{
+       /* Test that BigUnsignedInABase(std::string) constructor rejects digits
+        * too big for the specified base.
+        * Bug reported by Niakam Kazemi. */
+       TEST(BigUnsignedInABase("f", 10)); //error
+}
+
 } catch (const char *err) {
        cout << "UNCAUGHT ERROR: " << err << endl;
 }