summaryrefslogtreecommitdiff
path: root/third_party/bigint/BigUnsigned.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/BigUnsigned.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/BigUnsigned.cc')
-rw-r--r--third_party/bigint/BigUnsigned.cc30
1 files changed, 30 insertions, 0 deletions
diff --git a/third_party/bigint/BigUnsigned.cc b/third_party/bigint/BigUnsigned.cc
index d7f9889cc6..863fadcb39 100644
--- a/third_party/bigint/BigUnsigned.cc
+++ b/third_party/bigint/BigUnsigned.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 "BigUnsigned.hh"
// Memory management definitions have moved to the bottom of NumberlikeArray.hh.
@@ -189,8 +195,12 @@ void BigUnsigned::subtract(const BigUnsigned &a, const BigUnsigned &b) {
return;
} else if (a.len < b.len)
// If a is shorter than b, the result is negative.
+#ifdef FOXIT_CHROME_BUILD
+ abort();
+#else
throw "BigUnsigned::subtract: "
"Negative result in unsigned calculation";
+#endif
// Some variables...
bool borrowIn, borrowOut;
Blk temp;
@@ -223,7 +233,11 @@ void BigUnsigned::subtract(const BigUnsigned &a, const BigUnsigned &b) {
* predictable state. */
if (borrowIn) {
len = 0;
+#ifdef FOXIT_CHROME_BUILD
+ abort();
+#else
throw "BigUnsigned::subtract: Negative result in unsigned calculation";
+#endif
} else
// Copy over the rest of the blocks
for (; i < a.len; i++)
@@ -386,7 +400,11 @@ void BigUnsigned::divideWithRemainder(const BigUnsigned &b, BigUnsigned &q) {
* It would be silly to try to write quotient and remainder to the
* same variable. Rule that out right away. */
if (this == &q)
+#ifdef FOXIT_CHROME_BUILD
+ abort();
+#else
throw "BigUnsigned::divideWithRemainder: Cannot write quotient and remainder into the same variable";
+#endif
/* Now *this and q are separate, so the only concern is that b might be
* aliased to one of them. If so, use a temporary copy of b. */
if (this == &b || &q == &b) {
@@ -596,8 +614,12 @@ void BigUnsigned::bitShiftLeft(const BigUnsigned &a, int b) {
DTRT_ALIASED(this == &a, bitShiftLeft(a, b));
if (b < 0) {
if (b << 1 == 0)
+#ifdef FOXIT_CHROME_BUILD
+ abort();
+#else
throw "BigUnsigned::bitShiftLeft: "
"Pathological shift amount not implemented";
+#endif
else {
bitShiftRight(a, -b);
return;
@@ -622,8 +644,12 @@ void BigUnsigned::bitShiftRight(const BigUnsigned &a, int b) {
DTRT_ALIASED(this == &a, bitShiftRight(a, b));
if (b < 0) {
if (b << 1 == 0)
+#ifdef FOXIT_CHROME_BUILD
+ abort();
+#else
throw "BigUnsigned::bitShiftRight: "
"Pathological shift amount not implemented";
+#endif
else {
bitShiftLeft(a, -b);
return;
@@ -679,7 +705,11 @@ void BigUnsigned::operator ++(int) {
// Prefix decrement
void BigUnsigned::operator --() {
if (len == 0)
+#ifdef FOXIT_CHROME_BUILD
+ abort();
+#else
throw "BigUnsigned::operator --(): Cannot decrement an unsigned zero";
+#endif
Index i;
bool borrow = true;
for (i = 0; borrow; i++) {