This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author xdegaye
Recipients benjamin.peterson, xdegaye
Date 2018-01-05.12:27:44
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1515155264.34.0.467229070634.issue32441@psf.upfronthosting.co.za>
In-reply-to
Content
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)
History
Date User Action Args
2018-01-05 12:27:44xdegayesetrecipients: + xdegaye, benjamin.peterson
2018-01-05 12:27:44xdegayesetmessageid: <1515155264.34.0.467229070634.issue32441@psf.upfronthosting.co.za>
2018-01-05 12:27:44xdegayelinkissue32441 messages
2018-01-05 12:27:44xdegayecreate