summaryrefslogtreecommitdiffstats
path: root/Objects/longobject.c
diff options
context:
space:
mode:
authorHongWeipeng <961365124@qq.com>2019-11-26 07:54:49 (GMT)
committerInada Naoki <songofacandy@gmail.com>2019-11-26 07:54:49 (GMT)
commit036fe85bd3e6cd01093d836d71792a1966f961e8 (patch)
treecc1147b732a9913d34134641b321b15ddff47707 /Objects/longobject.c
parent386d00cc341b549800776b906bfc6b20ea40c7db (diff)
downloadcpython-036fe85bd3e6cd01093d836d71792a1966f961e8.zip
cpython-036fe85bd3e6cd01093d836d71792a1966f961e8.tar.gz
cpython-036fe85bd3e6cd01093d836d71792a1966f961e8.tar.bz2
bpo-27145: small_ints[x] could be returned in long_add and long_sub (GH-15716)
Diffstat (limited to 'Objects/longobject.c')
-rw-r--r--Objects/longobject.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/Objects/longobject.c b/Objects/longobject.c
index 294308e..f056797 100644
--- a/Objects/longobject.c
+++ b/Objects/longobject.c
@@ -3206,7 +3206,7 @@ x_sub(PyLongObject *a, PyLongObject *b)
if (sign < 0) {
Py_SIZE(z) = -Py_SIZE(z);
}
- return long_normalize(z);
+ return maybe_small_long(long_normalize(z));
}
static PyObject *
@@ -3254,13 +3254,15 @@ long_sub(PyLongObject *a, PyLongObject *b)
return PyLong_FromLong(MEDIUM_VALUE(a) - MEDIUM_VALUE(b));
}
if (Py_SIZE(a) < 0) {
- if (Py_SIZE(b) < 0)
- z = x_sub(a, b);
- else
+ if (Py_SIZE(b) < 0) {
+ z = x_sub(b, a);
+ }
+ else {
z = x_add(a, b);
- if (z != NULL) {
- assert(Py_SIZE(z) == 0 || Py_REFCNT(z) == 1);
- Py_SIZE(z) = -(Py_SIZE(z));
+ if (z != NULL) {
+ assert(Py_SIZE(z) == 0 || Py_REFCNT(z) == 1);
+ Py_SIZE(z) = -(Py_SIZE(z));
+ }
}
}
else {