]> granicus.if.org Git - python/commitdiff
longobject.c: add an assertion to ensure that MEDIUM_VALUE() is only called on
authorVictor Stinner <victor.stinner@gmail.com>
Wed, 17 Jul 2013 20:33:42 +0000 (22:33 +0200)
committerVictor Stinner <victor.stinner@gmail.com>
Wed, 17 Jul 2013 20:33:42 +0000 (22:33 +0200)
small integers (0 or 1 digit)

Objects/longobject.c

index a894ec5a642327ac38d42154f8f6984cfddf39fa..925e55a138bd8ff9f1da035dd050d085f0e665b5 100644 (file)
@@ -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))