[Python-checkins] cpython: Coverity: model PyLong_From*() functions

christian.heimes python-checkins at python.org
Fri Jul 26 18:00:22 CEST 2013


http://hg.python.org/cpython/rev/7e69961d82b2
changeset:   84842:7e69961d82b2
user:        Christian Heimes <christian at cheimes.de>
date:        Fri Jul 26 18:00:12 2013 +0200
summary:
  Coverity: model PyLong_From*() functions

files:
  Misc/coverity_model.c |  35 ++++++++++++++++++++++++++----
  1 files changed, 30 insertions(+), 5 deletions(-)


diff --git a/Misc/coverity_model.c b/Misc/coverity_model.c
--- a/Misc/coverity_model.c
+++ b/Misc/coverity_model.c
@@ -19,8 +19,10 @@
 /* dummy definitions, in most cases struct fields aren't required. */
 
 #define NULL (void *)0
+#define assert(op) /* empty */
 typedef int sdigit;
 typedef long Py_ssize_t;
+typedef long long PY_LONG_LONG;
 typedef unsigned short wchar_t;
 typedef struct {} PyObject;
 typedef struct {} grammar;
@@ -37,15 +39,38 @@
 /* Objects/longobject.c
  * NEGATIVE_RETURNS false positive */
 
-static PyObject small_ints[257 + 5];
-
 static PyObject *get_small_int(sdigit ival)
 {
+    /* Never returns NULL */
     PyObject *p;
-    if (((ival + 5) >= 0) && ((ival + 5) < 257 + 5)) {
-        return &small_ints[ival + 5];
+    assert(p != NULL);
+    return p;
+}
+
+PyObject *PyLong_FromLong(long ival)
+{
+    PyObject *p;
+    int maybe;
+
+    if ((ival >= -5) && (ival < 257 + 5)) {
+        p = get_small_int(ival);
+        assert(p != NULL);
+        return p;
     }
-    return p;
+    if (maybe)
+        return p;
+    else
+        return NULL;
+}
+
+PyObject *PyLong_FromLongLong(PY_LONG_LONG ival)
+{
+    return PyLong_FromLong((long)ival);
+}
+
+PyObject *PyLong_FromSsize_t(Py_ssize_t ival)
+{
+    return PyLong_FromLong((long)ival);
 }
 
 /* tainted sinks

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


More information about the Python-checkins mailing list