Skip to content

Commit b94767f

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

36 files changed

+69
-84
lines changed

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

Modules/_ssl.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,6 @@ static PyObject *PySSL_SSLdo_handshake(PySSLSocket *self)
354354

355355
/* Actually negotiate SSL connection */
356356
/* XXX If SSL_do_handshake() returns 0, it's also a failure. */
357-
sockstate = 0;
358357
do {
359358
PySSL_BEGIN_ALLOW_THREADS
360359
ret = SSL_do_handshake(self->ssl);
@@ -1090,7 +1089,6 @@ static PyObject *PySSL_SSLwrite(PySSLSocket *self, PyObject *args)
10901089
goto error;
10911090
}
10921091
do {
1093-
err = 0;
10941092
PySSL_BEGIN_ALLOW_THREADS
10951093
len = SSL_write(self->ssl, buf.buf, buf.len);
10961094
err = SSL_get_error(self->ssl, len);
@@ -1226,7 +1224,6 @@ static PyObject *PySSL_SSLread(PySSLSocket *self, PyObject *args)
12261224
}
12271225
}
12281226
do {
1229-
err = 0;
12301227
PySSL_BEGIN_ALLOW_THREADS
12311228
count = SSL_read(self->ssl, mem, len);
12321229
err = SSL_get_error(self->ssl, count);

Modules/_threadmodule.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,9 @@ acquire_timed(PyThread_type_lock lock, PY_TIMEOUT_T microseconds)
5353
_PyTime_timeval curtime;
5454
_PyTime_timeval endtime;
5555

56+
57+
_PyTime_gettimeofday(&endtime);
5658
if (microseconds > 0) {
57-
_PyTime_gettimeofday(&endtime);
5859
endtime.tv_sec += microseconds / (1000 * 1000);
5960
endtime.tv_usec += microseconds % (1000 * 1000);
6061
}

Modules/_tkinter.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2005,7 +2005,7 @@ static int
20052005
PythonCmd(ClientData clientData, Tcl_Interp *interp, int argc, char *argv[])
20062006
{
20072007
PythonCmd_ClientData *data = (PythonCmd_ClientData *)clientData;
2008-
PyObject *self, *func, *arg, *res;
2008+
PyObject *func, *arg, *res;
20092009
int i, rv;
20102010
Tcl_Obj *obj_res;
20112011

@@ -2014,7 +2014,6 @@ PythonCmd(ClientData clientData, Tcl_Interp *interp, int argc, char *argv[])
20142014
/* TBD: no error checking here since we know, via the
20152015
* Tkapp_CreateCommand() that the client data is a two-tuple
20162016
*/
2017-
self = data->self;
20182017
func = data->func;
20192018

20202019
/* Create argument list (argv1, ..., argvN) */

Modules/arraymodule.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -876,7 +876,6 @@ array_inplace_repeat(arrayobject *self, Py_ssize_t n)
876876
if (Py_SIZE(self) > 0) {
877877
if (n < 0)
878878
n = 0;
879-
items = self->ob_item;
880879
if ((self->ob_descr->itemsize != 0) &&
881880
(Py_SIZE(self) > PY_SSIZE_T_MAX / self->ob_descr->itemsize)) {
882881
return PyErr_NoMemory();

Modules/audioop.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,6 @@ audioop_findfit(PyObject *self, PyObject *args)
513513

514514
best_result = result;
515515
best_j = 0;
516-
j = 0;
517516

518517
for ( j=1; j<=len1-len2; j++) {
519518
aj_m1 = (double)cp1[j-1];
@@ -599,7 +598,6 @@ audioop_findmax(PyObject *self, PyObject *args)
599598

600599
best_result = result;
601600
best_j = 0;
602-
j = 0;
603601

604602
for ( j=1; j<=len1-len2; j++) {
605603
aj_m1 = (double)cp1[j-1];
@@ -1433,7 +1431,6 @@ audioop_lin2adpcm(PyObject *self, PyObject *args)
14331431
if ( state == Py_None ) {
14341432
/* First time, it seems. Set defaults */
14351433
valpred = 0;
1436-
step = 7;
14371434
index = 0;
14381435
} else if ( !PyArg_ParseTuple(state, "ii", &valpred, &index) )
14391436
return 0;
@@ -1534,7 +1531,6 @@ audioop_adpcm2lin(PyObject *self, PyObject *args)
15341531
if ( state == Py_None ) {
15351532
/* First time, it seems. Set defaults */
15361533
valpred = 0;
1537-
step = 7;
15381534
index = 0;
15391535
} else if ( !PyArg_ParseTuple(state, "ii", &valpred, &index) )
15401536
return 0;

Modules/cjkcodecs/_codecs_iso2022.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ struct iso2022_config {
123123

124124
CODEC_INIT(iso2022)
125125
{
126-
const struct iso2022_designation *desig = CONFIG_DESIGNATIONS;
126+
const struct iso2022_designation *desig;
127127
for (desig = CONFIG_DESIGNATIONS; desig->mark; desig++)
128128
if (desig->initializer != NULL && desig->initializer() != 0)
129129
return -1;

Modules/cjkcodecs/multibytecodec.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,7 @@ multibytecodec_encode(MultibyteCodec *codec,
483483
return PyBytes_FromStringAndSize(NULL, 0);
484484

485485
buf.excobj = NULL;
486+
buf.outobj = NULL;
486487
buf.inbuf = buf.inbuf_top = *data;
487488
buf.inbuf_end = buf.inbuf_top + datalen;
488489

Modules/main.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -577,15 +577,14 @@ Py_Main(int argc, wchar_t **argv)
577577
if ((p = Py_GETENV("PYTHONEXECUTABLE")) && *p != '\0') {
578578
wchar_t* buffer;
579579
size_t len = strlen(p);
580-
size_t r;
581580

582581
buffer = malloc(len * sizeof(wchar_t));
583582
if (buffer == NULL) {
584583
Py_FatalError(
585584
"not enough memory to copy PYTHONEXECUTABLE");
586585
}
587586

588-
r = mbstowcs(buffer, p, len);
587+
mbstowcs(buffer, p, len);
589588
Py_SetProgramName(buffer);
590589
/* buffer is now handed off - do not free */
591590
} else {

Modules/socketmodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3407,7 +3407,7 @@ socket_gethostbyaddr(PyObject *self, PyObject *args)
34073407
goto finally;
34083408
af = sa->sa_family;
34093409
ap = NULL;
3410-
al = 0;
3410+
/* al = 0; */
34113411
switch (af) {
34123412
case AF_INET:
34133413
ap = (char *)&((struct sockaddr_in *)sa)->sin_addr;

Objects/bytearrayobject.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2439,7 +2439,7 @@ If the argument is omitted, strip trailing ASCII whitespace.");
24392439
static PyObject *
24402440
bytearray_rstrip(PyByteArrayObject *self, PyObject *args)
24412441
{
2442-
Py_ssize_t left, right, mysize, argsize;
2442+
Py_ssize_t right, mysize, argsize;
24432443
void *myptr, *argptr;
24442444
PyObject *arg = Py_None;
24452445
Py_buffer varg;
@@ -2457,11 +2457,10 @@ bytearray_rstrip(PyByteArrayObject *self, PyObject *args)
24572457
}
24582458
myptr = self->ob_bytes;
24592459
mysize = Py_SIZE(self);
2460-
left = 0;
24612460
right = rstrip_helper(myptr, mysize, argptr, argsize);
24622461
if (arg != Py_None)
24632462
PyBuffer_Release(&varg);
2464-
return PyByteArray_FromStringAndSize(self->ob_bytes + left, right - left);
2463+
return PyByteArray_FromStringAndSize(self->ob_bytes, right);
24652464
}
24662465

24672466
PyDoc_STRVAR(decode_doc,

Objects/fileobject.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,8 +297,8 @@ Py_UniversalNewlineFgets(char *buf, int n, FILE *stream, PyObject *fobj)
297297
*p++ = c;
298298
if (c == '\n') break;
299299
}
300-
if ( c == EOF && skipnextlf )
301-
newlinetypes |= NEWLINE_CR;
300+
/* if ( c == EOF && skipnextlf )
301+
newlinetypes |= NEWLINE_CR; */
302302
FUNLOCKFILE(stream);
303303
*p = '\0';
304304
if ( skipnextlf ) {

Objects/floatobject.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,6 @@ PyFloat_FromString(PyObject *v)
197197
Py_DECREF(s_buffer);
198198
return NULL;
199199
}
200-
last = s + len;
201200
}
202201
else if (PyObject_AsCharBuffer(v, &s, &len)) {
203202
PyErr_SetString(PyExc_TypeError,
@@ -2246,7 +2245,7 @@ _PyFloat_Pack8(double x, unsigned char *p, int le)
22462245

22472246
/* Eighth byte */
22482247
*p = flo & 0xFF;
2249-
p += incr;
2248+
/* p += incr; */
22502249

22512250
/* Done */
22522251
return 0;

Objects/obmalloc.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1775,7 +1775,6 @@ _PyObject_DebugMallocStats(void)
17751775
* will be living in full pools -- would be a shame to miss them.
17761776
*/
17771777
for (i = 0; i < maxarenas; ++i) {
1778-
uint poolsinarena;
17791778
uint j;
17801779
uptr base = arenas[i].address;
17811780

@@ -1784,7 +1783,6 @@ _PyObject_DebugMallocStats(void)
17841783
continue;
17851784
narenas += 1;
17861785

1787-
poolsinarena = arenas[i].ntotalpools;
17881786
numfreepools += arenas[i].nfreepools;
17891787

17901788
/* round up to pool alignment */

Objects/tupleobject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ PyTuple_New(register Py_ssize_t size)
8686
{
8787
return PyErr_NoMemory();
8888
}
89-
nbytes += sizeof(PyTupleObject) - sizeof(PyObject *);
89+
/* nbytes += sizeof(PyTupleObject) - sizeof(PyObject *); */
9090

9191
op = PyObject_GC_NewVar(PyTupleObject, &PyTuple_Type, size);
9292
if (op == NULL)

0 commit comments

Comments
 (0)