php-src icon indicating copy to clipboard operation
php-src copied to clipboard

sapi/phpdbg/phpdbg.c:861: 2 * wrong operator ?

Open dcb314 opened this issue 4 years ago • 3 comments

Description

I just compiled php-8.1.4 with the new compiler clang-14. It said:

php-8.1.4/sapi/phpdbg/phpdbg.c:861:7: warning: use of bitwise '|' with boolean operands [-Wbitwise-instead-of-logical] php-8.1.4/sapi/phpdbg/phpdbg.c:861:8: warning: use of bitwise '&' with boolean operands [-Wbitwise-instead-of-logical]

Source code is

            if (((fstat(fileno(stderr), &stat[2]) < 0) & (fstat(fileno(stdout), &stat[0]) < 0)) | (fstat(data->fd, &stat[1]) < 0)) {

Maybe better code:

            if (((fstat(fileno(stderr), &stat[2]) < 0) && (fstat(fileno(stdout), &stat[0]) < 0)) || (fstat(data->fd, &stat[1]) < 0)) {

PHP Version

pgp 8.1.4

Operating System

Linux fedora 36 beta

dcb314 avatar Apr 05 '22 18:04 dcb314

It seems to me the use of the bitwise operators is by design; using logical operators instead could lead to short-circuit behavior, so that stat may not be properly initialized. Still, I'd change that code to do the statting upfront, and the use logical operators in the if-clause.

cc @bwoebi

cmb69 avatar Apr 07 '22 10:04 cmb69

Yeah, I agree. But yes, it's to ensure all fstat()s happen.

bwoebi avatar Apr 07 '22 11:04 bwoebi

Reclassifying as feature request, since there is no actual bug.

cmb69 avatar Apr 26 '22 12:04 cmb69