Message 309503 - Python tracker (original) (raw)
gcc is a little bit lost and prints now the following (false) warning:
gcc -pthread -Wno-unused-result -Wsign-compare -g -Og -Wall -Wstrict-prototypes -std=c99 -Wextra -Wno-unused-result -Wno-unused-parameter -Wno-missing-field-initializers -Werror=implicit-function-declaration -I. -I./Include -DPy_BUILD_CORE -c ./Modules/posixmodule.c -o Modules/posixmodule.o./Modules/posixmodule.c: In function ‘os_dup2_impl’: ./Modules/posixmodule.c:7785:9: warning: ‘res’ may be used uninitialized in this function [-Wmaybe-uninitialized] int res; ^~~
The following change fools gcc that does not print anymore the warning:
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 47b79fcc79..90d73daf97 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -7845,7 +7845,7 @@ os_dup2_impl(PyObject *module, int fd, int fd2, int inheritable) } }
- if (inheritable || dup3_works == 0)
- if (inheritable || (!inheritable && dup3_works == 0)) {
#endif Py_BEGIN_ALLOW_THREADS
The change does not modify the behavior:
- dup3_works == 0 is equivalent to ((inheritable && dup3_works == 0) || (!inheritable && dup3_works == 0))
- (inheritable && dup3_works == 0) is always false
- hence dup3_works == 0 is equivalent to (!inheritable && dup3_works == 0)