Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8cda5e6

Browse files
committed
Coverity: model PyLong_From*() functions
1 parent ebf4204 commit 8cda5e6

1 file changed

Lines changed: 30 additions & 5 deletions

File tree

Misc/coverity_model.c

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@
1919
/* dummy definitions, in most cases struct fields aren't required. */
2020

2121
#define NULL (void *)0
22+
#define assert(op) /* empty */
2223
typedef int sdigit;
2324
typedef long Py_ssize_t;
25+
typedef long long PY_LONG_LONG;
2426
typedef unsigned short wchar_t;
2527
typedef struct {} PyObject;
2628
typedef struct {} grammar;
@@ -37,17 +39,40 @@ void Py_FatalError(const char *msg) {
3739
/* Objects/longobject.c
3840
* NEGATIVE_RETURNS false positive */
3941

40-
static PyObject small_ints[257 + 5];
41-
4242
static PyObject *get_small_int(sdigit ival)
4343
{
44+
/* Never returns NULL */
4445
PyObject *p;
45-
if (((ival + 5) >= 0) && ((ival + 5) < 257 + 5)) {
46-
return &small_ints[ival + 5];
47-
}
46+
assert(p != NULL);
4847
return p;
4948
}
5049

50+
PyObject *PyLong_FromLong(long ival)
51+
{
52+
PyObject *p;
53+
int maybe;
54+
55+
if ((ival >= -5) && (ival < 257 + 5)) {
56+
p = get_small_int(ival);
57+
assert(p != NULL);
58+
return p;
59+
}
60+
if (maybe)
61+
return p;
62+
else
63+
return NULL;
64+
}
65+
66+
PyObject *PyLong_FromLongLong(PY_LONG_LONG ival)
67+
{
68+
return PyLong_FromLong((long)ival);
69+
}
70+
71+
PyObject *PyLong_FromSsize_t(Py_ssize_t ival)
72+
{
73+
return PyLong_FromLong((long)ival);
74+
}
75+
5176
/* tainted sinks
5277
*
5378
* Coverity considers argv, environ, read() data etc as tained.

0 commit comments

Comments
 (0)