Skip to content

cleanup: fix -Wmissing-braces warning in net_adapter_linux#134

Merged
nmoinvaz merged 1 commit into
masterfrom
nm/master/missing-braces-warning
May 1, 2026
Merged

cleanup: fix -Wmissing-braces warning in net_adapter_linux#134
nmoinvaz merged 1 commit into
masterfrom
nm/master/missing-braces-warning

Conversation

@nmoinvaz

@nmoinvaz nmoinvaz commented Apr 29, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Clang's -Wmissing-braces flagged struct ifreq ifr = {0}; because the first member of struct ifreq is a union.
  • Replaced with memset-based zero initialization, matching the existing style used four lines above for adapter.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed initialization in Linux network adapter operations to prevent uninitialized state when querying interface details. This ensures more reliable detection of interface name, flags, and hardware address and reduces intermittent failures or incorrect results when enumerating network adapters.

@nmoinvaz nmoinvaz added the warnings fix Fixes to compiler warnings label Apr 29, 2026
@nmoinvaz nmoinvaz requested a review from sergio-nsk April 29, 2026 03:45
@coderabbitai

coderabbitai Bot commented Apr 29, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: faec56b9-48eb-4eb9-9b28-3ecd0e1a4f35

📥 Commits

Reviewing files that changed from the base of the PR and between 121e5de and e2f33dd.

📒 Files selected for processing (1)
  • net_adapter_linux.c
✅ Files skipped from review due to trivial changes (1)
  • net_adapter_linux.c

📝 Walkthrough

Walkthrough

The pull request updates net_adapter_linux.c to replace the inline {0} initializer with an explicit memset(&ifr, 0, sizeof(ifr)) after declaring struct ifreq ifr, ensuring the ifr instance is zeroed before setting fields and performing ioctl calls.

Changes

Cohort / File(s) Summary
Struct Initialization Change
net_adapter_linux.c
Replaced inline zero-initializer for struct ifreq ifr with an explicit memset(&ifr, 0, sizeof(ifr)) immediately after declaration; subsequent assignments (ifr.ifr_ifindex) and ioctl calls remain unchanged.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Poem

🐰 A struct once left to chance and fate,
Now memset hops in—clean slate!
Fields start fresh, no mystery in sight,
ioctl calls sleep easy through the night. 🥕

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title directly and specifically describes the main change: fixing a compiler warning (-Wmissing-braces) in the net_adapter_linux file, which aligns perfectly with the changeset that replaces brace-based initialization with memset-based initialization.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch nm/master/missing-braces-warning

Review rate limit: 3/5 reviews remaining, refill in 22 minutes and 8 seconds.

Comment @coderabbitai help to get the list of available commands and usage tips.

@nmoinvaz nmoinvaz enabled auto-merge (rebase) April 29, 2026 03:46

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
net_adapter_linux.c (1)

45-73: ⚠️ Potential issue | 🟠 Major

Use an explicit socket error check (fd >= 0) instead of if (fd)

if (fd) is incorrect for socket(): -1 means failure, but 0 is a valid descriptor. With fd == 0, this code wrongly skips all ioctl calls and also skips close(fd), causing incorrect behavior and resource leaks.

Suggested fix
-        int fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP);
-        if (fd) {
+        int fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP);
+        if (fd >= 0) {
             struct ifreq ifr;
             memset(&ifr, 0, sizeof(ifr));
@@
             close(fd);
         } else {
             strncat(adapter.name, ifa->ifa_name, sizeof(adapter.name) - 1);
         }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@net_adapter_linux.c` around lines 45 - 73, The socket success check is wrong:
replace the `if (fd)` test after `int fd = socket(AF_INET, SOCK_DGRAM,
IPPROTO_IP);` with an explicit `fd >= 0` check so valid descriptor 0 is treated
as success; ensure all ioctl calls and the `close(fd)` occur inside that `fd >=
0` branch and that the failure path (when socket returns -1) still falls back to
copying `ifa->ifa_name` into `adapter.name`. Update uses of `fd`, `socket(...)`,
and `close(fd)` accordingly to avoid skipping ioctls or leaking the descriptor.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@net_adapter_linux.c`:
- Around line 45-73: The socket success check is wrong: replace the `if (fd)`
test after `int fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP);` with an explicit
`fd >= 0` check so valid descriptor 0 is treated as success; ensure all ioctl
calls and the `close(fd)` occur inside that `fd >= 0` branch and that the
failure path (when socket returns -1) still falls back to copying
`ifa->ifa_name` into `adapter.name`. Update uses of `fd`, `socket(...)`, and
`close(fd)` accordingly to avoid skipping ioctls or leaking the descriptor.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: a225c794-d096-4ff7-807c-6c0ebfd6bdf4

📥 Commits

Reviewing files that changed from the base of the PR and between d8e1181 and 121e5de.

📒 Files selected for processing (1)
  • net_adapter_linux.c

@codecov-commenter

codecov-commenter commented Apr 29, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 60.93%. Comparing base (df114f1) to head (e2f33dd).
⚠️ Report is 11 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #134      +/-   ##
==========================================
+ Coverage   58.57%   60.93%   +2.35%     
==========================================
  Files          32       33       +1     
  Lines        2607     2813     +206     
  Branches      526      527       +1     
==========================================
+ Hits         1527     1714     +187     
- Misses        745      787      +42     
+ Partials      335      312      -23     
Flag Coverage Δ
macos 60.93% <ø> (+5.85%) ⬆️
macos_duktape ?

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

The first member of struct ifreq is a union, so clang's
-Wmissing-braces flagged `struct ifreq ifr = {0};`. Zero-initialize
with memset to match the surrounding style.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@nmoinvaz nmoinvaz force-pushed the nm/master/missing-braces-warning branch from 121e5de to e2f33dd Compare April 29, 2026 03:47
@nmoinvaz nmoinvaz changed the title Fix -Wmissing-braces warning in net_adapter_linux cleanup: fix -Wmissing-braces warning in net_adapter_linux Apr 29, 2026
Comment thread net_adapter_linux.c
Comment on lines +47 to +48
struct ifreq ifr;
memset(&ifr, 0, sizeof(ifr));

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not this change as it wanted?

Suggested change
struct ifreq ifr;
memset(&ifr, 0, sizeof(ifr));
struct ifreq ifr = {{0}};

This seems also valid in C

Suggested change
struct ifreq ifr;
memset(&ifr, 0, sizeof(ifr));
struct ifreq ifr = {{}};

@nmoinvaz nmoinvaz merged commit 4fd6e35 into master May 1, 2026
16 checks passed
@nmoinvaz nmoinvaz deleted the nm/master/missing-braces-warning branch May 1, 2026 06:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

warnings fix Fixes to compiler warnings

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants