Initialize variables to prevent GCC warnings

This commit is contained in:
Victor Stinner 2015-03-18 15:02:06 +01:00
parent 938b0b9fee
commit 0c39b1b970
3 changed files with 25 additions and 18 deletions

View file

@ -3469,7 +3469,8 @@ PyUnicode_DecodeLocaleAndSize(const char *str, Py_ssize_t len,
int surrogateescape; int surrogateescape;
size_t error_pos; size_t error_pos;
char *errmsg; char *errmsg;
PyObject *reason, *exc; PyObject *reason = NULL; /* initialize to prevent gcc warning */
PyObject *exc;
if (locale_error_handler(errors, &surrogateescape) < 0) if (locale_error_handler(errors, &surrogateescape) < 0)
return NULL; return NULL;
@ -9454,7 +9455,7 @@ handle_capital_sigma(int kind, void *data, Py_ssize_t length, Py_ssize_t i)
{ {
Py_ssize_t j; Py_ssize_t j;
int final_sigma; int final_sigma;
Py_UCS4 c; Py_UCS4 c = 0; /* initialize to prevent gcc warning */
/* U+03A3 is in the Final_Sigma context when, it is found like this: /* U+03A3 is in the Final_Sigma context when, it is found like this:
\p{cased}\p{case-ignorable}*U+03A3!(\p{case-ignorable}*\p{cased}) \p{cased}\p{case-ignorable}*U+03A3!(\p{case-ignorable}*\p{cased})
@ -11124,7 +11125,7 @@ interpreted as in slice notation.");
static PyObject * static PyObject *
unicode_count(PyObject *self, PyObject *args) unicode_count(PyObject *self, PyObject *args)
{ {
PyObject *substring; PyObject *substring = NULL; /* initialize to fix a compiler warning */
Py_ssize_t start = 0; Py_ssize_t start = 0;
Py_ssize_t end = PY_SSIZE_T_MAX; Py_ssize_t end = PY_SSIZE_T_MAX;
PyObject *result; PyObject *result;
@ -11312,9 +11313,10 @@ Return -1 on failure.");
static PyObject * static PyObject *
unicode_find(PyObject *self, PyObject *args) unicode_find(PyObject *self, PyObject *args)
{ {
PyObject *substring; /* initialize variables to prevent gcc warning */
Py_ssize_t start; PyObject *substring = NULL;
Py_ssize_t end; Py_ssize_t start = 0;
Py_ssize_t end = 0;
Py_ssize_t result; Py_ssize_t result;
if (!stringlib_parse_args_finds_unicode("find", args, &substring, 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.");
static PyObject * static PyObject *
unicode_index(PyObject *self, PyObject *args) unicode_index(PyObject *self, PyObject *args)
{ {
/* initialize variables to prevent gcc warning */
Py_ssize_t result; Py_ssize_t result;
PyObject *substring; PyObject *substring = NULL;
Py_ssize_t start; Py_ssize_t start = 0;
Py_ssize_t end; Py_ssize_t end = 0;
if (!stringlib_parse_args_finds_unicode("index", args, &substring, if (!stringlib_parse_args_finds_unicode("index", args, &substring,
&start, &end)) &start, &end))
@ -12477,9 +12480,10 @@ Return -1 on failure.");
static PyObject * static PyObject *
unicode_rfind(PyObject *self, PyObject *args) unicode_rfind(PyObject *self, PyObject *args)
{ {
PyObject *substring; /* initialize variables to prevent gcc warning */
Py_ssize_t start; PyObject *substring = NULL;
Py_ssize_t end; Py_ssize_t start = 0;
Py_ssize_t end = 0;
Py_ssize_t result; Py_ssize_t result;
if (!stringlib_parse_args_finds_unicode("rfind", args, &substring, 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.");
static PyObject * static PyObject *
unicode_rindex(PyObject *self, PyObject *args) unicode_rindex(PyObject *self, PyObject *args)
{ {
PyObject *substring; /* initialize variables to prevent gcc warning */
Py_ssize_t start; PyObject *substring = NULL;
Py_ssize_t end; Py_ssize_t start = 0;
Py_ssize_t end = 0;
Py_ssize_t result; Py_ssize_t result;
if (!stringlib_parse_args_finds_unicode("rindex", args, &substring, if (!stringlib_parse_args_finds_unicode("rindex", args, &substring,

View file

@ -164,6 +164,8 @@ validate_expr(expr_ty exp, expr_context_ty ctx)
return 0; return 0;
} }
check_ctx = 0; check_ctx = 0;
/* set actual_ctx to prevent gcc warning */
actual_ctx = 0;
} }
if (check_ctx && actual_ctx != ctx) { if (check_ctx && actual_ctx != ctx) {
PyErr_Format(PyExc_ValueError, "expression must have %s context but has %s instead", PyErr_Format(PyExc_ValueError, "expression must have %s context but has %s instead",

View file

@ -53,7 +53,7 @@ builtin___build_class__(PyObject *self, PyObject *args, PyObject *kwds)
PyObject *func, *name, *bases, *mkw, *meta, *winner, *prep, *ns, *cell; PyObject *func, *name, *bases, *mkw, *meta, *winner, *prep, *ns, *cell;
PyObject *cls = NULL; PyObject *cls = NULL;
Py_ssize_t nargs; Py_ssize_t nargs;
int isclass; int isclass = 0; /* initialize to prevent gcc warning */
assert(args != NULL); assert(args != NULL);
if (!PyTuple_Check(args)) { if (!PyTuple_Check(args)) {