[Python-checkins] cpython: longobject.c: add an assertion to ensure that MEDIUM_VALUE() is only called on

victor.stinner python-checkins at python.org
Wed Jul 17 22:34:00 CEST 2013


http://hg.python.org/cpython/rev/3e7683c49620
changeset:   84699:3e7683c49620
user:        Victor Stinner <victor.stinner at gmail.com>
date:        Wed Jul 17 22:33:42 2013 +0200
summary:
  longobject.c: add an assertion to ensure that MEDIUM_VALUE() is only called on
small integers (0 or 1 digit)

files:
  Objects/longobject.c |  3 ++-
  1 files changed, 2 insertions(+), 1 deletions(-)


diff --git a/Objects/longobject.c b/Objects/longobject.c
--- a/Objects/longobject.c
+++ b/Objects/longobject.c
@@ -17,7 +17,8 @@
 #endif
 
 /* convert a PyLong of size 1, 0 or -1 to an sdigit */
-#define MEDIUM_VALUE(x) (Py_SIZE(x) < 0 ? -(sdigit)(x)->ob_digit[0] :   \
+#define MEDIUM_VALUE(x) (assert(-1 <= Py_SIZE(x) && Py_SIZE(x) <= 1),   \
+         Py_SIZE(x) < 0 ? -(sdigit)(x)->ob_digit[0] :   \
              (Py_SIZE(x) == 0 ? (sdigit)0 :                             \
               (sdigit)(x)->ob_digit[0]))
 #define ABS(x) ((x) < 0 ? -(x) : (x))

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list