Opened 8 years ago
Closed 8 years ago
#12825 closed bug (fixed)
[Patch] net_buffer.cpp: Fix clang warning
Reported by: | mt | Owned by: | axeld |
---|---|---|---|
Priority: | normal | Milestone: | Unscheduled |
Component: | Network & Internet/Stack | Version: | R1/Development |
Keywords: | Cc: | ||
Blocked By: | Blocking: | ||
Platform: | All |
Description
In remove_header(), 'while (left >= 0)' at line 1823 is always true because 'left' is unsigned. so I think we may change condition to 'while (left > 0)'.
/home/haiku/haiku/haiku/src/add-ons/kernel/network/stack/net_buffer.cpp:1823:14: warning: comparison of unsigned expression >= 0 is always true [-Wtautological-compare] while (left >= 0) { ~~~~ ^ ~
Attachments (1)
Change History (8)
by , 8 years ago
Attachment: | 0012-net_buffer.cpp-fix-clang-warning.patch added |
---|
comment:1 by , 8 years ago
patch: | 0 → 1 |
---|
comment:2 by , 8 years ago
comment:3 by , 8 years ago
From my understanding of the code, the only way the loop ought to be exited is through the break
statement in line 1827 and the return
statement in line 1829. Therefore, putting while (true)
should be appropriate. On the other hand, one might argue that while (left >= 0)
, despite doing nothing in practice, more clearly demonstrates the purpose of the loop (i.e. removing all bytes that are left).
comment:4 by , 8 years ago
I'd prefer to use a while (true)
loop here; especially since leaving it like this produces a warning, and is also slightly confusing for those who expect loop conditions make sense, and don't just hint at the intended usage :-)
In any case, the suggested patch is not correct, and would break the code, nice catch, Adrien!
comment:5 by , 8 years ago
patch: | 1 → 0 |
---|
comment:6 by , 8 years ago
Status: | new → in-progress |
---|
comment:7 by , 8 years ago
Resolution: | → fixed |
---|---|
Status: | in-progress → closed |
Fixed in hrev50429. Thanks mt for reporting!
I'm not sure this is right, especially as the code inside the loop does handle "left == 0". Either we should make "left" signed, or change the loop into a "while true" if there are other ways to exit it.