[Python-checkins] bpo-38425: Fix ‘res’ may be used uninitialized warning (GH-16688)

Miss Islington (bot) webhook-mailer at python.org
Thu Oct 10 04:00:30 EDT 2019


https://github.com/python/cpython/commit/6b6935e563562c427d5bb1b2864d6a2fed0e74fa
commit: 6b6935e563562c427d5bb1b2864d6a2fed0e74fa
branch: 3.8
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: GitHub <noreply at github.com>
date: 2019-10-10T01:00:19-07:00
summary:

bpo-38425: Fix ‘res’ may be used uninitialized warning (GH-16688)

(cherry picked from commit a05fcd3c7adf6e3a0944da8cf80a3346882e9b3b)

Co-authored-by: Dong-hee Na <donghee.na92 at gmail.com>

files:
M Parser/asdl_c.py
M Python/Python-ast.c

diff --git a/Parser/asdl_c.py b/Parser/asdl_c.py
index f4fa271b6595b..574fcb0e2faaf 100644
--- a/Parser/asdl_c.py
+++ b/Parser/asdl_c.py
@@ -1191,7 +1191,6 @@ class PartingShots(StaticVisitor):
 /* mode is 0 for "exec", 1 for "eval" and 2 for "single" input */
 mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode)
 {
-    mod_ty res;
     PyObject *req_type[3];
     char *req_name[] = {"Module", "Expression", "Interactive"};
     int isinstance;
@@ -1217,6 +1216,8 @@ class PartingShots(StaticVisitor):
                      req_name[mode], Py_TYPE(ast)->tp_name);
         return NULL;
     }
+
+    mod_ty res = NULL;
     if (obj2ast_mod(ast, &res, arena) != 0)
         return NULL;
     else
diff --git a/Python/Python-ast.c b/Python/Python-ast.c
index fd96964a1e77e..f73f035845f8c 100644
--- a/Python/Python-ast.c
+++ b/Python/Python-ast.c
@@ -8991,7 +8991,6 @@ PyObject* PyAST_mod2obj(mod_ty t)
 /* mode is 0 for "exec", 1 for "eval" and 2 for "single" input */
 mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode)
 {
-    mod_ty res;
     PyObject *req_type[3];
     char *req_name[] = {"Module", "Expression", "Interactive"};
     int isinstance;
@@ -9017,6 +9016,8 @@ mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode)
                      req_name[mode], Py_TYPE(ast)->tp_name);
         return NULL;
     }
+
+    mod_ty res = NULL;
     if (obj2ast_mod(ast, &res, arena) != 0)
         return NULL;
     else



More information about the Python-checkins mailing list