summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorTim Peters <tim.peters@gmail.com>2002-08-20 19:00:22 (GMT)
committerTim Peters <tim.peters@gmail.com>2002-08-20 19:00:22 (GMT)
commit0d2d87d202c62182983c9d7edce978a0c9c9aad1 (patch)
tree0244207cba1e0783d42f08d11b534746100060fe /Objects
parent76afbd9aa41bf34f488a7a1e759622c7f1830cff (diff)
downloadcpython-0d2d87d202c62182983c9d7edce978a0c9c9aad1.zip
cpython-0d2d87d202c62182983c9d7edce978a0c9c9aad1.tar.gz
cpython-0d2d87d202c62182983c9d7edce978a0c9c9aad1.tar.bz2
long_format(), long_lshift(): Someone on c.l.py is trying to boost
SHIFT and MASK, and widen digit. One problem is that code of the form digit << small_integer implicitly assumes that the result fits in an int or unsigned int (platform-dependent, but "int sized" in any case), since digit is promoted "just" to int or unsigned via the usual integer promotions. But if digit is typedef'ed as unsigned int, this loses information. The cure for this is just to cast digit to twodigits first.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/longobject.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/Objects/longobject.c b/Objects/longobject.c
index 856230e..9e641af 100644
--- a/Objects/longobject.c
+++ b/Objects/longobject.c
@@ -949,7 +949,7 @@ long_format(PyObject *aa, int base, int addL)
++basebits;
for (i = 0; i < size_a; ++i) {
- accum |= a->ob_digit[i] << accumbits;
+ accum |= (twodigits)a->ob_digit[i] << accumbits;
accumbits += SHIFT;
assert(accumbits >= basebits);
do {
@@ -2345,7 +2345,7 @@ long_lshift(PyObject *v, PyObject *w)
z->ob_digit[i] = 0;
accum = 0;
for (i = wordshift, j = 0; j < oldsize; i++, j++) {
- accum |= a->ob_digit[j] << remshift;
+ accum |= (twodigits)a->ob_digit[j] << remshift;
z->ob_digit[i] = (digit)(accum & MASK);
accum >>= SHIFT;
}