Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix warning caused by nonsense break condition #1324

Merged
merged 1 commit into from
Dec 12, 2022

Conversation

bi4k8
Copy link
Collaborator

@bi4k8 bi4k8 commented Dec 12, 2022

Checklist

  • I have described the changes
  • I have linked to any relevant GitHub issues, if applicable
  • Documentation in doc/ has been updated
  • All new code is licensed under GPLv3

Description

This fixes a warning that appeared with cmake .. -DMAINTAINER_MODE=ON on Linux:

[1/4] Building CXX object src/CMakeFiles/conky_core.dir/linux.cc.o
FAILED: src/CMakeFiles/conky_core.dir/linux.cc.o 
/usr/bin/c++ -D_LARGEFILE64_SOURCE -D_POSIX_C_SOURCE=200809L -I3rdparty/toluapp/include -Ibuild-maint -I/usr/include/freetype2 -Ibuild-maint/data -ggdb -Wall -W -Wextra -Wunused -pedantic -Werror -Wno-format -Wno-unknown-pragmas -Wno-error=pragmas -Wimplicit-fallthrough=2 -std=c++17 -MD -MT src/CMakeFiles/conky_core.dir/linux.cc.o -MF src/CMakeFiles/conky_core.dir/linux.cc.o.d -o src/CMakeFiles/conky_core.dir/linux.cc.o -c src/linux.cc
src/linux.cc: In function 'void update_net_interfaces(FILE*, bool, double)':
src/linux.cc:581:44: error: comparing the result of pointer addition '(((ifreq*)conf.ifconf::ifc_ifcu.ifconf::<unnamed union>::ifcu_buf) + ((sizetype)(((long unsigned int)k) * 40)))' and NULL [-Werror=address]
  581 |       if (!(((struct ifreq *)conf.ifc_buf) + k)) break;
      |            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
cc1plus: all warnings being treated as errors
ninja: build stopped: subcommand failed.

The commit message explains why the warning appeared and why the condition was never triggered (and was motivated by a condition that could not occur). Runtime behavior remains the same.

There are no relevant issues I could find, and this is just a fix for compilation, so no docs need to be changed.

This checks if a pointer offset from a heap-allocated buffer is NULL,
which is only true if the buffer is NULL and the offset is zero.

It appears to be attempting to check if an entry in an array of
pointers is zero before dereferencing that entry, but the SIOCGIFCONF
ioctl actually writes `struct ifreq` entries (not pointers to them)
into the `ifc_buf` buffer.

Furthermore, because `ifc_buf` is in a union with `struct ifreq
*ifc_req`, we can simply access `ifc_req` instead of casting `ifc_buf`
each time.
@netlify
Copy link

netlify bot commented Dec 12, 2022

Deploy Preview for conkyweb canceled.

Name Link
🔨 Latest commit b060c39
🔍 Latest deploy log https://app.netlify.com/sites/conkyweb/deploys/6397808b10c8aa00086fae9a

@github-actions github-actions bot added the sources PR modifies project sources label Dec 12, 2022
@brndnmtthws brndnmtthws merged commit f3ffd17 into brndnmtthws:main Dec 12, 2022
@bi4k8 bi4k8 deleted the fix-ioctl-warning branch December 12, 2022 19:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sources PR modifies project sources
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants