Skip to content

Commit ba5bf06

Browse files
committed
Initialize variables to prevent GCC warnings
1 parent 2636a23 commit ba5bf06

3 files changed

Lines changed: 25 additions & 18 deletions

File tree

Objects/unicodeobject.c

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3469,7 +3469,8 @@ PyUnicode_DecodeLocaleAndSize(const char *str, Py_ssize_t len,
34693469
int surrogateescape;
34703470
size_t error_pos;
34713471
char *errmsg;
3472-
PyObject *reason, *exc;
3472+
PyObject *reason = NULL; /* initialize to prevent gcc warning */
3473+
PyObject *exc;
34733474

34743475
if (locale_error_handler(errors, &surrogateescape) < 0)
34753476
return NULL;
@@ -9454,7 +9455,7 @@ handle_capital_sigma(int kind, void *data, Py_ssize_t length, Py_ssize_t i)
94549455
{
94559456
Py_ssize_t j;
94569457
int final_sigma;
9457-
Py_UCS4 c;
9458+
Py_UCS4 c = 0; /* initialize to prevent gcc warning */
94589459
/* U+03A3 is in the Final_Sigma context when, it is found like this:
94599460
94609461
\p{cased}\p{case-ignorable}*U+03A3!(\p{case-ignorable}*\p{cased})
@@ -11124,7 +11125,7 @@ interpreted as in slice notation.");
1112411125
static PyObject *
1112511126
unicode_count(PyObject *self, PyObject *args)
1112611127
{
11127-
PyObject *substring;
11128+
PyObject *substring = NULL; /* initialize to fix a compiler warning */
1112811129
Py_ssize_t start = 0;
1112911130
Py_ssize_t end = PY_SSIZE_T_MAX;
1113011131
PyObject *result;
@@ -11312,9 +11313,10 @@ Return -1 on failure.");
1131211313
static PyObject *
1131311314
unicode_find(PyObject *self, PyObject *args)
1131411315
{
11315-
PyObject *substring;
11316-
Py_ssize_t start;
11317-
Py_ssize_t end;
11316+
/* initialize variables to prevent gcc warning */
11317+
PyObject *substring = NULL;
11318+
Py_ssize_t start = 0;
11319+
Py_ssize_t end = 0;
1131811320
Py_ssize_t result;
1131911321

1132011322
if (!stringlib_parse_args_finds_unicode("find", args, &substring,
@@ -11399,10 +11401,11 @@ Like S.find() but raise ValueError when the substring is not found.");
1139911401
static PyObject *
1140011402
unicode_index(PyObject *self, PyObject *args)
1140111403
{
11404+
/* initialize variables to prevent gcc warning */
1140211405
Py_ssize_t result;
11403-
PyObject *substring;
11404-
Py_ssize_t start;
11405-
Py_ssize_t end;
11406+
PyObject *substring = NULL;
11407+
Py_ssize_t start = 0;
11408+
Py_ssize_t end = 0;
1140611409

1140711410
if (!stringlib_parse_args_finds_unicode("index", args, &substring,
1140811411
&start, &end))
@@ -12477,9 +12480,10 @@ Return -1 on failure.");
1247712480
static PyObject *
1247812481
unicode_rfind(PyObject *self, PyObject *args)
1247912482
{
12480-
PyObject *substring;
12481-
Py_ssize_t start;
12482-
Py_ssize_t end;
12483+
/* initialize variables to prevent gcc warning */
12484+
PyObject *substring = NULL;
12485+
Py_ssize_t start = 0;
12486+
Py_ssize_t end = 0;
1248312487
Py_ssize_t result;
1248412488

1248512489
if (!stringlib_parse_args_finds_unicode("rfind", args, &substring,
@@ -12513,9 +12517,10 @@ Like S.rfind() but raise ValueError when the substring is not found.");
1251312517
static PyObject *
1251412518
unicode_rindex(PyObject *self, PyObject *args)
1251512519
{
12516-
PyObject *substring;
12517-
Py_ssize_t start;
12518-
Py_ssize_t end;
12520+
/* initialize variables to prevent gcc warning */
12521+
PyObject *substring = NULL;
12522+
Py_ssize_t start = 0;
12523+
Py_ssize_t end = 0;
1251912524
Py_ssize_t result;
1252012525

1252112526
if (!stringlib_parse_args_finds_unicode("rindex", args, &substring,

Python/ast.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ validate_arguments(arguments_ty args)
115115
}
116116
if (!validate_args(args->kwonlyargs))
117117
return 0;
118-
if (args->kwarg && args->kwarg->annotation
118+
if (args->kwarg && args->kwarg->annotation
119119
&& !validate_expr(args->kwarg->annotation, Load)) {
120120
return 0;
121121
}
@@ -164,6 +164,8 @@ validate_expr(expr_ty exp, expr_context_ty ctx)
164164
return 0;
165165
}
166166
check_ctx = 0;
167+
/* set actual_ctx to prevent gcc warning */
168+
actual_ctx = 0;
167169
}
168170
if (check_ctx && actual_ctx != ctx) {
169171
PyErr_Format(PyExc_ValueError, "expression must have %s context but has %s instead",
@@ -451,7 +453,7 @@ validate_exprs(asdl_seq *exprs, expr_context_ty ctx, int null_ok)
451453
"None disallowed in expression list");
452454
return 0;
453455
}
454-
456+
455457
}
456458
return 1;
457459
}

Python/bltinmodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ builtin___build_class__(PyObject *self, PyObject *args, PyObject *kwds)
5353
PyObject *func, *name, *bases, *mkw, *meta, *winner, *prep, *ns, *cell;
5454
PyObject *cls = NULL;
5555
Py_ssize_t nargs;
56-
int isclass;
56+
int isclass = 0; /* initialize to prevent gcc warning */
5757

5858
assert(args != NULL);
5959
if (!PyTuple_Check(args)) {

0 commit comments

Comments
 (0)