Skip to content

Commit 66a5912

Browse files
committed
Cautious (probably unnecessary) protection against overflows
1 parent 4c0095e commit 66a5912

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

Source/NSDecimal.m

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,10 @@ but small numbers can only be represented with limited exactness (one digit
111111
GS_DECLARE void
112112
NSDecimalCopy(NSDecimal *destination, const NSDecimal *source)
113113
{
114-
memcpy(destination, source, sizeof(NSDecimal));
114+
if (destination != source)
115+
{
116+
memcpy(destination, source, sizeof(NSDecimal));
117+
}
115118
}
116119

117120
static void
@@ -1566,7 +1569,7 @@ static void DecimalToCharvec(const NSDecimal *n, GSDecimal *m)
15661569
else
15671570
carry = 0;
15681571
// This is one off to allow final carry
1569-
n.cMantissa[j+1] = e;
1572+
if (j < l->length-1) n.cMantissa[j+1] = e;
15701573
}
15711574
n.cMantissa[0] = carry;
15721575
NSDecimalCompact(&n);
@@ -1654,7 +1657,7 @@ static void DecimalToCharvec(const NSDecimal *n, GSDecimal *m)
16541657
error1 = NSDecimalSubtract(&n1, &n1, r, mode);
16551658
if (NSCalculationNoError != error1)
16561659
error = error1;
1657-
result->cMantissa[k-1]++;
1660+
if (k > 0) result->cMantissa[k-1]++;
16581661
}
16591662

16601663
return error;

0 commit comments

Comments
 (0)