summaryrefslogtreecommitdiff
path: root/third_party/bigint/BigInteger.cc
diff options
context:
space:
mode:
authorBo Xu <bo_xu@foxitsoftware.com>2014-12-02 16:34:20 -0800
committerBo Xu <bo_xu@foxitsoftware.com>2014-12-02 16:34:20 -0800
commit91dd8c77ae849c22a8e4c9275e3f728b474b5be5 (patch)
tree79c1805c6a18ab234053f79fc4e10edabad5eef1 /third_party/bigint/BigInteger.cc
parent44047c3300d07192a67b1714084cc2d43b1e9bd9 (diff)
downloadpdfium-91dd8c77ae849c22a8e4c9275e3f728b474b5be5.tar.xz
Modify big integer library
This patch follows https://pdfium.googlesource.com/pdfium/+/44047c3300d07192a67b1714084cc2d43b1e9bd9 Modify the library to resolve compile error, add copyright notice and change pdfium.gyp and BUILD.gn R=tsepez@chromium.org Review URL: https://codereview.chromium.org/754743003
Diffstat (limited to 'third_party/bigint/BigInteger.cc')
-rw-r--r--third_party/bigint/BigInteger.cc38
1 files changed, 38 insertions, 0 deletions
diff --git a/third_party/bigint/BigInteger.cc b/third_party/bigint/BigInteger.cc
index 3b23aa1e7b..bac578f974 100644
--- a/third_party/bigint/BigInteger.cc
+++ b/third_party/bigint/BigInteger.cc
@@ -1,3 +1,9 @@
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code by Matt McCutchen, see the LICENSE file.
+
#include "BigInteger.hh"
void BigInteger::operator =(const BigInteger &x) {
@@ -14,7 +20,11 @@ BigInteger::BigInteger(const Blk *b, Index blen, Sign s) : mag(b, blen) {
switch (s) {
case zero:
if (!mag.isZero())
+#ifdef FOXIT_CHROME_BUILD
+ abort();
+#else
throw "BigInteger::BigInteger(const Blk *, Index, Sign): Cannot use a sign of zero with a nonzero magnitude";
+#endif
sign = zero;
break;
case positive:
@@ -25,7 +35,11 @@ BigInteger::BigInteger(const Blk *b, Index blen, Sign s) : mag(b, blen) {
default:
/* g++ seems to be optimizing out this case on the assumption
* that the sign is a valid member of the enumeration. Oh well. */
+#ifdef FOXIT_CHROME_BUILD
+ abort();
+#else
throw "BigInteger::BigInteger(const Blk *, Index, Sign): Invalid sign";
+#endif
}
}
@@ -33,7 +47,11 @@ BigInteger::BigInteger(const BigUnsigned &x, Sign s) : mag(x) {
switch (s) {
case zero:
if (!mag.isZero())
+#ifdef FOXIT_CHROME_BUILD
+ abort();
+#else
throw "BigInteger::BigInteger(const BigUnsigned &, Sign): Cannot use a sign of zero with a nonzero magnitude";
+#endif
sign = zero;
break;
case positive:
@@ -44,7 +62,11 @@ BigInteger::BigInteger(const BigUnsigned &x, Sign s) : mag(x) {
default:
/* g++ seems to be optimizing out this case on the assumption
* that the sign is a valid member of the enumeration. Oh well. */
+#ifdef FOXIT_CHROME_BUILD
+ abort();
+#else
throw "BigInteger::BigInteger(const BigUnsigned &, Sign): Invalid sign";
+#endif
}
}
@@ -92,8 +114,12 @@ inline X convertBigUnsignedToPrimitiveAccess(const BigUnsigned &a) {
template <class X>
X BigInteger::convertToUnsignedPrimitive() const {
if (sign == negative)
+#ifdef FOXIT_CHROME_BUILD
+ abort();
+#else
throw "BigInteger::to<Primitive>: "
"Cannot convert a negative integer to an unsigned type";
+#endif
else
return convertBigUnsignedToPrimitiveAccess<X>(mag);
}
@@ -120,8 +146,12 @@ X BigInteger::convertToSignedPrimitive() const {
}
// Otherwise fall through.
}
+#ifdef FOXIT_CHROME_BUILD
+ abort();
+#else
throw "BigInteger::to<Primitive>: "
"Value is too big to fit in the requested type";
+#endif
}
unsigned long BigInteger::toUnsignedLong () const { return convertToUnsignedPrimitive<unsigned long > (); }
@@ -149,7 +179,11 @@ BigInteger::CmpRes BigInteger::compareTo(const BigInteger &x) const {
// Compare the magnitudes, but return the opposite result
return CmpRes(-mag.compareTo(x.mag));
default:
+#ifdef FOXIT_CHROME_BUILD
+ abort();
+#else
throw "BigInteger internal error";
+#endif
}
}
@@ -281,7 +315,11 @@ void BigInteger::divideWithRemainder(const BigInteger &b, BigInteger &q) {
// Defend against aliased calls;
// same idea as in BigUnsigned::divideWithRemainder .
if (this == &q)
+#ifdef FOXIT_CHROME_BUILD
+ abort();
+#else
throw "BigInteger::divideWithRemainder: Cannot write quotient and remainder into the same variable";
+#endif
if (this == &b || &q == &b) {
BigInteger tmpB(b);
divideWithRemainder(tmpB, q);