Bitwise OR instead of logical one in test_aio.c

Started by Mikhail Gribkov3 days ago5 messageshackers

Thread notes

1 note#refactor
hackorum-bot#refactor
hackorum-bot
2 days ago

@global #refactor

#refactor
Jump to latest
#1Mikhail Gribkov
youzhick@gmail.com

Hi hackers,

I've noticed an odd check in test_aio.c:
if (zero_on_error | zero_damaged_pages)
srb_flags |= READ_BUFFERS_ZERO_ON_ERROR;

Both zero_on_error and zero_damaged_pages declared as bool. Shouldn't
there be a logical "||" inside the if-condition, not a bitwise "|"?
Yes, it works now, but fixing it would be cleaner.

Proposed patch is attached (although it's quite trivial).

--
best regards,
Mikhail A. Gribkov

Attachments:

t259838_1
001_Fix_bitwise_operation_on_bools.patchapplication/octet-stream; name=001_Fix_bitwise_operation_on_bools.patchDownload+1-1
#2Chao Li
li.evan.chao@gmail.com
In reply to: Mikhail Gribkov (#1)
Re: Bitwise OR instead of logical one in test_aio.c

On Nov 26, 2026, at 05:02, Mikhail Gribkov <youzhick@gmail.com> wrote:

Hi hackers,

I've noticed an odd check in test_aio.c:
if (zero_on_error | zero_damaged_pages)
srb_flags |= READ_BUFFERS_ZERO_ON_ERROR;

Both zero_on_error and zero_damaged_pages declared as bool. Shouldn't there be a logical "||" inside the if-condition, not a bitwise "|"?
Yes, it works now, but fixing it would be cleaner.

For two boolean variables “a" and “b", "a | b" and "a || b" will produce the same result, so there is no correctness issue. But I agree fixing that improves readability.

Proposed patch is attached (although it's quite trivial).

--
best regards,
Mikhail A. Gribkov

<001_Fix_bitwise_operation_on_bools.patch>

LGTM.

Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/

#3Xuneng Zhou
xunengzhou@gmail.com
In reply to: Mikhail Gribkov (#1)
Re: Bitwise OR instead of logical one in test_aio.c

Hi Mikhail,

On Thu, Nov 26, 2026 at 5:02 AM Mikhail Gribkov <youzhick@gmail.com> wrote:

Hi hackers,

I've noticed an odd check in test_aio.c:
if (zero_on_error | zero_damaged_pages)
srb_flags |= READ_BUFFERS_ZERO_ON_ERROR;

Both zero_on_error and zero_damaged_pages declared as bool. Shouldn't there be a logical "||" inside the if-condition, not a bitwise "|"?
Yes, it works now, but fixing it would be cleaner.

Proposed patch is attached (although it's quite trivial).

AI found another one in FuncnameGetCandidates() in namespace.c:

Assert(nargs >= 0 || !(expand_variadic | expand_defaults));

I think they belong to the same category and could be addressed together.

--
Regards,
Xuneng Zhou
HighGo Software Co., Ltd.

#4Mikhail Gribkov
youzhick@gmail.com
In reply to: Xuneng Zhou (#3)
Re: Bitwise OR instead of logical one in test_aio.c

AI found another one in FuncnameGetCandidates() in namespace.c:

Assert(nargs >= 0 || !(expand_variadic | expand_defaults));

I think they belong to the same category and could be addressed together.

Whoa, this one is 18 years old!

Yes, I agree these should be addressed together. Neither issue is truly
problematic, but cleaning up the code would be nice.
Attached is the V2-patch fixing both places.

--
best regards,
Mikhail A. Gribkov

On Thu, Nov 26, 2026 at 4:39 AM Xuneng Zhou <xunengzhou@gmail.com> wrote:

Show quoted text

Hi Mikhail,

On Thu, Nov 26, 2026 at 5:02 AM Mikhail Gribkov <youzhick@gmail.com>
wrote:

Hi hackers,

I've noticed an odd check in test_aio.c:
if (zero_on_error | zero_damaged_pages)
srb_flags |= READ_BUFFERS_ZERO_ON_ERROR;

Both zero_on_error and zero_damaged_pages declared as bool. Shouldn't

there be a logical "||" inside the if-condition, not a bitwise "|"?

Yes, it works now, but fixing it would be cleaner.

Proposed patch is attached (although it's quite trivial).

AI found another one in FuncnameGetCandidates() in namespace.c:

Assert(nargs >= 0 || !(expand_variadic | expand_defaults));

I think they belong to the same category and could be addressed together.

--
Regards,
Xuneng Zhou
HighGo Software Co., Ltd.

Attachments:

t259838_4
001_Fix_bitwise_operation_on_bools_v2.patchapplication/octet-stream; name=001_Fix_bitwise_operation_on_bools_v2.patchDownload+2-2
#5Heikki Linnakangas
hlinnaka@iki.fi
In reply to: Mikhail Gribkov (#4)
Re: Bitwise OR instead of logical one in test_aio.c

On 26/11/2026 09:53, Mikhail Gribkov wrote:

AI found another one in FuncnameGetCandidates() in namespace.c:

Assert(nargs >= 0 || !(expand_variadic | expand_defaults));

I think they belong to the same category and could be addressed together.

Whoa, this one is 18 years old!

Yes, I agree these should be addressed together. Neither issue is truly
problematic, but cleaning up the code would be nice.
Attached is the V2-patch fixing both places.

Committed, thanks.

- Heikki