Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1112)

Unified Diff: third_party/bigint/BigInteger.cc

Issue 754743003: Modify big integer library (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Add copyright notice Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/bigint/BigInteger.cc
diff --git a/third_party/bigint/BigInteger.cc b/third_party/bigint/BigInteger.cc
index 3b23aa1e7b25cb3c1573c826c5390979b43558f9..24088f6fce103916ed0e68d3362bab9810a8a1d6 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
Tom Sepez 2014/12/03 00:14:19 nit: . at end of sentence.
+
#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);
« no previous file with comments | « pdfium.gyp ('k') | third_party/bigint/BigInteger.hh » ('j') | third_party/bigint/BigUnsigned.hh » ('J')

Powered by Google App Engine
This is Rietveld 408576698