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

Skip to content

Commit b94767f

Browse files
committed
Issue #8914: fix various warnings from the Clang static analyzer v254.
1 parent 79da6b7 commit b94767f

36 files changed

Lines changed: 69 additions & 84 deletions

Include/pydebug.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ PyAPI_DATA(int) Py_UnbufferedStdioFlag;
2626
PYTHONPATH and PYTHONHOME from the environment */
2727
#define Py_GETENV(s) (Py_IgnoreEnvironmentFlag ? NULL : getenv(s))
2828

29-
PyAPI_FUNC(void) Py_FatalError(const char *message);
30-
3129
#ifdef __cplusplus
3230
}
3331
#endif

Include/pyerrors.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,17 @@ PyAPI_FUNC(PyObject *) PyErr_Occurred(void);
7070
PyAPI_FUNC(void) PyErr_Clear(void);
7171
PyAPI_FUNC(void) PyErr_Fetch(PyObject **, PyObject **, PyObject **);
7272
PyAPI_FUNC(void) PyErr_Restore(PyObject *, PyObject *, PyObject *);
73-
PyAPI_FUNC(void) Py_FatalError(const char *message);
73+
74+
#if defined(__clang__) || \
75+
(defined(__GNUC__) && \
76+
((__GNUC_MAJOR__ >= 3) || \
77+
(__GNUC_MAJOR__ == 2) && (__GNUC_MINOR__ >= 5)))
78+
#define _Py_NO_RETURN __attribute__((__noreturn__))
79+
#else
80+
#define _Py_NO_RETURN
81+
#endif
82+
83+
PyAPI_FUNC(void) Py_FatalError(const char *message) _Py_NO_RETURN;
7484

7585
#if defined(Py_DEBUG) || defined(Py_LIMITED_API)
7686
#define _PyErr_OCCURRED() PyErr_Occurred()

Modules/_ctypes/cfield.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ PyCField_FromDesc(PyObject *desc, Py_ssize_t index,
5252
{
5353
CFieldObject *self;
5454
PyObject *proto;
55-
Py_ssize_t size, align, length;
55+
Py_ssize_t size, align;
5656
SETFUNC setfunc = NULL;
5757
GETFUNC getfunc = NULL;
5858
StgDictObject *dict;
@@ -106,7 +106,6 @@ PyCField_FromDesc(PyObject *desc, Py_ssize_t index,
106106
}
107107

108108
size = dict->size;
109-
length = dict->length;
110109
proto = desc;
111110

112111
/* Field descriptors for 'c_char * n' are be scpecial cased to

Modules/_datetimemodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1461,7 +1461,7 @@ delta_to_microseconds(PyDateTime_Delta *self)
14611461
goto Done;
14621462
Py_DECREF(x1);
14631463
Py_DECREF(x2);
1464-
x1 = x2 = NULL;
1464+
/* x1 = */ x2 = NULL;
14651465

14661466
/* x3 has days+seconds in seconds */
14671467
x1 = PyNumber_Multiply(x3, us_per_second); /* us */

Modules/_io/bytesio.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -938,13 +938,11 @@ static int
938938
bytesiobuf_getbuffer(bytesiobuf *obj, Py_buffer *view, int flags)
939939
{
940940
int ret;
941-
void *ptr;
942941
bytesio *b = (bytesio *) obj->source;
943942
if (view == NULL) {
944943
b->exports++;
945944
return 0;
946945
}
947-
ptr = (void *) obj;
948946
ret = PyBuffer_FillInfo(view, (PyObject*)obj, b->buf, b->string_size,
949947
0, flags);
950948
if (ret >= 0) {

Modules/_json.c

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ scanstring_unicode(PyObject *pystr, Py_ssize_t end, int strict, Py_ssize_t *next
335335
PyObject *rval = NULL;
336336
Py_ssize_t len = PyUnicode_GET_SIZE(pystr);
337337
Py_ssize_t begin = end - 1;
338-
Py_ssize_t next = begin;
338+
Py_ssize_t next /* = begin */;
339339
const Py_UNICODE *buf = PyUnicode_AS_UNICODE(pystr);
340340
PyObject *chunks = NULL;
341341
PyObject *chunk = NULL;
@@ -1532,13 +1532,12 @@ encoder_listencode_dict(PyEncoderObject *s, PyObject *rval, PyObject *dct, Py_ss
15321532
goto bail;
15331533
Py_CLEAR(ident);
15341534
}
1535+
/* TODO DOES NOT RUN; dead code
15351536
if (s->indent != Py_None) {
1536-
/* TODO: DOES NOT RUN */
15371537
indent_level -= 1;
1538-
/*
1539-
yield '\n' + (' ' * (_indent * _current_indent_level))
1540-
*/
1541-
}
1538+
1539+
yield '\n' + (' ' * (_indent * _current_indent_level))
1540+
}*/
15421541
if (PyList_Append(rval, close_dict))
15431542
goto bail;
15441543
return 0;
@@ -1624,13 +1623,13 @@ encoder_listencode_list(PyEncoderObject *s, PyObject *rval, PyObject *seq, Py_ss
16241623
goto bail;
16251624
Py_CLEAR(ident);
16261625
}
1626+
1627+
/* TODO: DOES NOT RUN
16271628
if (s->indent != Py_None) {
1628-
/* TODO: DOES NOT RUN */
16291629
indent_level -= 1;
1630-
/*
1631-
yield '\n' + (' ' * (_indent * _current_indent_level))
1632-
*/
1633-
}
1630+
1631+
yield '\n' + (' ' * (_indent * _current_indent_level))
1632+
}*/
16341633
if (PyList_Append(rval, close_array))
16351634
goto bail;
16361635
Py_DECREF(s_fast);

Modules/_multiprocessing/multiprocessing.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#define PY_SSIZE_T_CLEAN
55

66
#ifdef __sun
7-
/* The control message API is only available on Solaris
7+
/* The control message API is only available on Solaris
88
if XPG 4.2 or later is requested. */
99
#define _XOPEN_SOURCE 500
1010
#endif

Modules/_sqlite/connection.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -673,16 +673,13 @@ void _pysqlite_final_callback(sqlite3_context* context)
673673
{
674674
PyObject* function_result = NULL;
675675
PyObject** aggregate_instance;
676-
PyObject* aggregate_class;
677676

678677
#ifdef WITH_THREAD
679678
PyGILState_STATE threadstate;
680679

681680
threadstate = PyGILState_Ensure();
682681
#endif
683682

684-
aggregate_class = (PyObject*)sqlite3_user_data(context);
685-
686683
aggregate_instance = (PyObject**)sqlite3_aggregate_context(context, sizeof(PyObject*));
687684
if (!*aggregate_instance) {
688685
/* this branch is executed if there was an exception in the aggregate's

Modules/_sqlite/cursor.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,9 @@ static int pysqlite_cursor_init(pysqlite_Cursor* self, PyObject* args, PyObject*
126126

127127
static void pysqlite_cursor_dealloc(pysqlite_Cursor* self)
128128
{
129-
int rc;
130-
131129
/* Reset the statement if the user has not closed the cursor */
132130
if (self->statement) {
133-
rc = pysqlite_statement_reset(self->statement);
131+
pysqlite_statement_reset(self->statement);
134132
Py_DECREF(self->statement);
135133
}
136134

@@ -529,7 +527,7 @@ PyObject* _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject*
529527

530528
if (self->statement != NULL) {
531529
/* There is an active statement */
532-
rc = pysqlite_statement_reset(self->statement);
530+
pysqlite_statement_reset(self->statement);
533531
}
534532

535533
operation_cstr = _PyUnicode_AsStringAndSize(operation, &operation_len);
@@ -734,7 +732,7 @@ PyObject* _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject*
734732
}
735733

736734
if (multiple) {
737-
rc = pysqlite_statement_reset(self->statement);
735+
pysqlite_statement_reset(self->statement);
738736
}
739737
Py_XDECREF(parameters);
740738
}

Modules/_sqlite/statement.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -369,11 +369,9 @@ void pysqlite_statement_mark_dirty(pysqlite_Statement* self)
369369

370370
void pysqlite_statement_dealloc(pysqlite_Statement* self)
371371
{
372-
int rc;
373-
374372
if (self->st) {
375373
Py_BEGIN_ALLOW_THREADS
376-
rc = sqlite3_finalize(self->st);
374+
sqlite3_finalize(self->st);
377375
Py_END_ALLOW_THREADS
378376
}
379377

0 commit comments

Comments
 (0)