Discussion:
CVS commit: src/tests/lib/libc/c063
(too old to reply)
Roland Illig
2024-07-10 04:37:26 UTC
Permalink
Am 10.07.2024 um 03:12 schrieb Christos Zoulas:

src/tests/lib/libc/c063/t_fchmodat.c
- ATF_REQUIRE(st.st_mode = 0600);
+ ATF_REQUIRE(st.st_mode == 0600);
Should we do something to detect bugs like these mechanically?

ATF_REQUIRE(cond) currently expands to "if (!(cond))", and I guess due
to the parentheses around "cond", GCC does not warn about the assignment
in the condition.

One idea is to rewrite ATF_REQUIRE to be "if (cond) {} else", which
would make GCC complain directly.

Another idea is to make lint warn about the pattern "!(a = b)", even
though its output is not looked upon by many people.

Roland


--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-***@muc.de
Christos Zoulas
2024-07-10 07:40:04 UTC
Permalink
Post by Roland Illig
src/tests/lib/libc/c063/t_fchmodat.c
- ATF_REQUIRE(st.st_mode = 0600);
+ ATF_REQUIRE(st.st_mode == 0600);
Should we do something to detect bugs like these mechanically?
ATF_REQUIRE(cond) currently expands to "if (!(cond))", and I guess due
to the parentheses around "cond", GCC does not warn about the assignment
in the condition.
One idea is to rewrite ATF_REQUIRE to be "if (cond) {} else", which
would make GCC complain directly.
Another idea is to make lint warn about the pattern "!(a = b)", even
though its output is not looked upon by many people.
Yes, I was thinking along the same lines. If the gcc construct does not
produce warnings, I would go with that.

christos


--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-***@muc.de
Loading...