Skip to content

Commit 88d5e2c

Browse files
authored
fix marshal uninitialized variable warnings (#4114)
GCC says: ../cpython/Python/marshal.c: In function ‘PyMarshal_WriteLongToFile’: ../cpython/Python/marshal.c:70:35: warning: ‘wf.ptr’ may be used uninitialized in this function [-Wmaybe-uninitialized] else if ((p)->ptr != (p)->end) *(p)->ptr++ = (c); \ ^~ ../cpython/Python/marshal.c:70:47: warning: ‘wf.end’ may be used uninitialized in this function [-Wmaybe-uninitialized] else if ((p)->ptr != (p)->end) *(p)->ptr++ = (c); \ ^~ ../cpython/Python/marshal.c:77:10: warning: ‘wf.str’ may be used uninitialized in this function [-Wmaybe-uninitialized] if (p->str == NULL) ~^~~~~ This isn't a real problem because if the file pointer is not NULL, the string-related fields are never touched. But, it doesn't hurt to set the unused fields to NULL.
1 parent 04c0a40 commit 88d5e2c

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

Python/marshal.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,9 @@ PyMarshal_WriteLongToFile(long x, FILE *fp, int version)
465465
{
466466
WFILE wf;
467467
wf.fp = fp;
468+
wf.str = NULL;
469+
wf.ptr = NULL;
470+
wf.end = NULL;
468471
wf.error = WFERR_OK;
469472
wf.depth = 0;
470473
wf.strings = NULL;
@@ -477,6 +480,9 @@ PyMarshal_WriteObjectToFile(PyObject *x, FILE *fp, int version)
477480
{
478481
WFILE wf;
479482
wf.fp = fp;
483+
wf.str = NULL;
484+
wf.ptr = NULL;
485+
wf.end = NULL;
480486
wf.error = WFERR_OK;
481487
wf.depth = 0;
482488
wf.strings = (version > 0) ? PyDict_New() : NULL;

0 commit comments

Comments
 (0)