aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--miscutils/bc.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/miscutils/bc.c b/miscutils/bc.c
index 5b48f84a1..33abe9366 100644
--- a/miscutils/bc.c
+++ b/miscutils/bc.c
@@ -1467,16 +1467,25 @@ static BcStatus bc_num_ulong(BcNum *n, unsigned long *result_p)
1467 1467
1468static void bc_num_ulong2num(BcNum *n, unsigned long val) 1468static void bc_num_ulong2num(BcNum *n, unsigned long val)
1469{ 1469{
1470 size_t len;
1471 BcDig *ptr; 1470 BcDig *ptr;
1472 unsigned long i;
1473 1471
1474 bc_num_zero(n); 1472 bc_num_zero(n);
1475 1473
1476 if (val == 0) return; 1474 if (val == 0) return;
1477 1475
1478 for (len = 1, i = ULONG_MAX; i != 0; i /= 10, ++len) bc_num_expand(n, len); 1476 if (ULONG_MAX == 0xffffffffUL)
1479 for (ptr = n->num, i = 0; val; ++i, ++n->len, val /= 10) ptr[i] = val % 10; 1477 bc_num_expand(n, 10); // 10 digits: 4294967295
1478 if (ULONG_MAX == 0xffffffffffffffffUL)
1479 bc_num_expand(n, 20); // 20 digits: 18446744073709551615
1480 BUILD_BUG_ON(ULONG_MAX > 0xffffffffffffffffUL);
1481
1482 ptr = n->num;
1483 for (;;) {
1484 n->len++;
1485 *ptr++ = val % 10;
1486 val /= 10;
1487 if (val == 0) break;
1488 }
1480} 1489}
1481 1490
1482static void bc_num_subArrays(BcDig *restrict a, BcDig *restrict b, 1491static void bc_num_subArrays(BcDig *restrict a, BcDig *restrict b,