Skip to content

Format code with clang-format v19#601

Merged
rsmarples merged 5 commits intomasterfrom
clang-format
Apr 30, 2026
Merged

Format code with clang-format v19#601
rsmarples merged 5 commits intomasterfrom
clang-format

Conversation

@rsmarples
Copy link
Copy Markdown
Member

Using a template taken from FreeBSD
Add a github action to enforce this

Using a template taken from FreeBSD
Add a github action to enforce this
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 30, 2026

Warning

Rate limit exceeded

@rsmarples has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 31 minutes and 46 seconds before requesting another review.

To keep reviews running without waiting, you can enable usage-based add-on for your organization. This allows additional reviews beyond the hourly cap. Account admins can enable it under billing.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 91539c91-3fd6-4755-b152-4559b19d4507

📥 Commits

Reviewing files that changed from the base of the PR and between 0001a26 and 9da1caa.

📒 Files selected for processing (1)
  • src/control.h

Walkthrough

Adds C/C++ formatting and linting configs (.clang-format, .clang-tidy, .clangd), a GitHub Actions format-check workflow, Makefile targets for format/lint, and applies widespread formatting-only updates across the src tree and some workflow files.

Changes

Cohort / File(s) Summary
Tool configs
.clang-format, .clang-tidy, .clangd
Adds clang-format rules (FreeBSD/WebKit style, include ordering), clang-tidy config (cert-* set, header filter), and clangd compileFlags adjustments (include vendor dirs, match C and headers).
CI workflow
.github/workflows/format.yml
Adds GitHub Action that runs clang-format v19 to check/validate formatting on src/**/*.c and src/**/*.h on pushes and PRs.
CI workflow edits
.github/workflows/build.yml
Disables/removes active BSD-target jobs (OpenBSD/FreeBSD/NetBSD) by commenting them out.
Top-level build include
src/Makefile, src/dev/Makefile
Changes Makefile include resolution to use local Makefile.inc and appends include in src/dev/Makefile.
Make targets
src/Makefile.inc
Adds check-format, format, and internal _lint targets invoking clang-format/clang-tidy and then includes ${TOP}/Makefile.inc.
Large-scale formatting
src/**/*.c, src/**/*.h (60+ files; examples below)
Bulk whitespace/brace/line-wrapping reformatting across many modules without semantic changes (arp, auth, bpf, common, control, dhcp*, dev, duid, if*, ipv4*, ipv6*, ipv6nd*, logerr, privsep*, queue.h, etc.).
Modules (representative)
src/arp.c, src/arp.h
Reordered includes and reformatted macros/decls; no behavioral change.
Modules (representative)
src/dhcp.c, src/dhcp.h, src/dhcp-common.c, src/dhcp-common.h
Compacted initializers, adjusted function signature wrapping and call-site formatting only.
Modules (representative)
src/ipv6.c, src/ipv6.h, src/ipv6nd.c, src/ipv6nd.h
Reordered includes, normalized macros, and reformatted signatures/blocks without changing logic.
Privilege separation
src/privsep.c, src/privsep.h, src/privsep-*.c, src/privsep-*.h
Consistent include ordering and formatting across privsep code; prototypes rewrapped only.
Utilities / headers
src/common.h, src/if.h, src/queue.h
Whitespace and macro-definition formatting normalized; one conditional macro spacing adjusted.

Sequence Diagram(s)

sequenceDiagram
    participant Dev as Developer
    participant GH as GitHub Actions
    participant Repo as Repository
    participant ClangFmt as clang-format Action
    participant ClangTidy as clang-tidy (Make target)

    Dev->>Repo: push / open PR
    GH->>Repo: workflow triggered (format.yml)
    GH->>ClangFmt: run clang-format v19 on `src/**/*.c` `src/**/*.h`
    ClangFmt-->>GH: report pass/fail
    alt format fails
      GH-->>Dev: report formatting failures in PR
    else format passes
      GH-->>Dev: report success
    end
    Note over Dev,ClangTidy: Local/CI make targets can run clang-tidy via `make check-format` / `_lint`
    Dev->>ClangTidy: invoke `make _lint` (adds -isystem vendor includes)
    ClangTidy-->>Dev: lint results
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 5.72% 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
Title check ✅ Passed The title clearly and specifically summarizes the main change: applying clang-format v19 formatting to the codebase, which is the primary focus of this large formatting PR.
Description check ✅ Passed The description directly relates to the changeset by mentioning the use of a FreeBSD clang-format template and the addition of a GitHub Action for enforcement, both of which are present in the PR.
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 unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch clang-format

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
Review rate limit: 0/1 reviews remaining, refill in 31 minutes and 46 seconds.

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

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Caution

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

⚠️ Outside diff range comments (1)
src/ipv4ll.c (1)

223-239: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Leak in test path due to overwritten allocation

At Line 225 an ia allocation is performed for DHCPCD_TEST, but at Line 237 ia is reassigned from ipv4_addaddr(...) unconditionally, leaking the first allocation.

Proposed fix
 	if (ia == NULL) {
 		if (ifp->ctx->options & DHCPCD_TEST) {
-			ia = malloc(sizeof(*ia));
+			ia = calloc(1, sizeof(*ia));
 			if (ia == NULL) {
 				logerr(__func__);
 				return;
 			}
 			ia->iface = ifp;
 			ia->addr = state->pickedaddr;
-		} else if (!(ifp->options->options & DHCPCD_CONFIGURE)) {
+		} else if (!(ifp->options->options & DHCPCD_CONFIGURE)) {
 			logwarnx("%s: refusing to add IPv4LL address %s",
 			    ifp->name, inet_ntoa(state->pickedaddr));
 			return;
+		} else {
+			ia = ipv4_addaddr(ifp, &state->pickedaddr, &inaddr_llmask,
+			    &inaddr_llbcast, DHCP_INFINITE_LIFETIME,
+			    DHCP_INFINITE_LIFETIME);
 		}
-		ia = ipv4_addaddr(ifp, &state->pickedaddr, &inaddr_llmask,
-		    &inaddr_llbcast, DHCP_INFINITE_LIFETIME,
-		    DHCP_INFINITE_LIFETIME);
 	}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/ipv4ll.c` around lines 223 - 239, The test-path allocates ia when
ifp->ctx->options & DHCPCD_TEST but then unconditionally overwrites ia with the
return of ipv4_addaddr(...), leaking the first allocation; fix by changing the
control flow so ipv4_addaddr(...) is only called when ia is still NULL (i.e.,
move or guard the ipv4_addaddr call behind an "if (ia == NULL)" branch) or
explicitly free the temporary ia before reassigning; reference symbols: ia,
ifp->ctx->options, DHCPCD_TEST, ipv4_addaddr().
🧹 Nitpick comments (2)
.github/workflows/format.yml (1)

7-9: ⚡ Quick win

Pin GitHub Actions to immutable commit SHAs.

Lines 7 and 9 use mutable tags (@v5). For CI supply-chain hardening, pin to full commit SHAs (at least for third-party actions).

Suggested update
-      - uses: actions/checkout@v5
+      - uses: actions/checkout@<full_commit_sha>
...
-      - uses: RafikFarhad/clang-format-github-action@v5
+      - uses: RafikFarhad/clang-format-github-action@<full_commit_sha>
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.github/workflows/format.yml around lines 7 - 9, Replace mutable action tags
with immutable commit SHAs: update the uses entries referencing
actions/checkout@v5 and RafikFarhad/clang-format-github-action@v5 to use their
corresponding full commit SHA pins (e.g., actions/checkout@<full-sha> and
RafikFarhad/clang-format-github-action@<full-sha>), ensuring you fetch the exact
commit SHAs from each action's repository and update the two uses lines
accordingly.
src/Makefile.inc (1)

2-7: ⚡ Quick win

Harden formatter file discovery and argument passing.

Line 2 and Line 6 use find | xargs in a form that can break on paths with spaces/newlines and may pass unintended arguments. Use null-delimited paths and restrict to regular files.

Proposed patch
 check-format:
-	find . -iname "*.c" -o -iname "*.h" | \
-		xargs clang-format --dry-run --Werror
+	find . -type f \( -iname "*.c" -o -iname "*.h" \) -print0 | \
+		xargs -0 -- clang-format --dry-run --Werror
 
 format:
-	find . -iname "*.c" -o -iname "*.h" | \
-		xargs clang-format -i
+	find . -type f \( -iname "*.c" -o -iname "*.h" \) -print0 | \
+		xargs -0 -- clang-format -i
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/Makefile.inc` around lines 2 - 7, The find|xargs pipeline in the format
and check rules can break on filenames with spaces/newlines and may pass
non-regular files; update both occurrences (the rule invoking clang-format
--dry-run --Werror and the format: rule invoking clang-format -i) to restrict to
regular files and use null-delimited path passing: e.g. use find with -type f
and grouped name tests like find . -type f \( -iname "*.c" -o -iname "*.h" \)
-print0 piped to xargs -0 clang-format ... (or use find ... -exec clang-format
{} +) so filenames with whitespace are handled safely and no unintended args are
passed.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In @.clangd:
- Around line 7-9: The PathMatch regex in .clangd is incorrect because it uses a
comma, so replace the current pattern "PathMatch: src/.*\.(c,h)" with a proper
alternation or character class (e.g., use "src/.*\.(c|h)" or "src/.*\.[ch]") so
that the rule matches files ending in .c or .h; update the PathMatch entry
accordingly.

In @.github/workflows/format.yml:
- Line 2: The workflow currently triggers only on the push event (the top-level
on key with value [push]); update the workflow trigger so it also runs on pull
requests by adding the pull_request event to the on configuration (e.g., change
the on array to include pull_request) so formatting checks run for PRs as well.

---

Outside diff comments:
In `@src/ipv4ll.c`:
- Around line 223-239: The test-path allocates ia when ifp->ctx->options &
DHCPCD_TEST but then unconditionally overwrites ia with the return of
ipv4_addaddr(...), leaking the first allocation; fix by changing the control
flow so ipv4_addaddr(...) is only called when ia is still NULL (i.e., move or
guard the ipv4_addaddr call behind an "if (ia == NULL)" branch) or explicitly
free the temporary ia before reassigning; reference symbols: ia,
ifp->ctx->options, DHCPCD_TEST, ipv4_addaddr().

---

Nitpick comments:
In @.github/workflows/format.yml:
- Around line 7-9: Replace mutable action tags with immutable commit SHAs:
update the uses entries referencing actions/checkout@v5 and
RafikFarhad/clang-format-github-action@v5 to use their corresponding full commit
SHA pins (e.g., actions/checkout@<full-sha> and
RafikFarhad/clang-format-github-action@<full-sha>), ensuring you fetch the exact
commit SHAs from each action's repository and update the two uses lines
accordingly.

In `@src/Makefile.inc`:
- Around line 2-7: The find|xargs pipeline in the format and check rules can
break on filenames with spaces/newlines and may pass non-regular files; update
both occurrences (the rule invoking clang-format --dry-run --Werror and the
format: rule invoking clang-format -i) to restrict to regular files and use
null-delimited path passing: e.g. use find with -type f and grouped name tests
like find . -type f \( -iname "*.c" -o -iname "*.h" \) -print0 piped to xargs -0
clang-format ... (or use find ... -exec clang-format {} +) so filenames with
whitespace are handled safely and no unintended args are passed.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 3794afca-47d4-4c8d-87ae-ee18749b3928

📥 Commits

Reviewing files that changed from the base of the PR and between 243ad84 and 2bccd05.

📒 Files selected for processing (66)
  • .clang-format
  • .clang-tidy
  • .clangd
  • .github/workflows/format.yml
  • src/Makefile
  • src/Makefile.inc
  • src/arp.c
  • src/arp.h
  • src/auth.c
  • src/auth.h
  • src/bpf.c
  • src/bpf.h
  • src/common.c
  • src/common.h
  • src/control.c
  • src/control.h
  • src/defs.h
  • src/dev.c
  • src/dev/udev.c
  • src/dhcp-common.c
  • src/dhcp-common.h
  • src/dhcp.c
  • src/dhcp.h
  • src/dhcp6.c
  • src/dhcp6.h
  • src/dhcpcd.c
  • src/dhcpcd.h
  • src/duid.c
  • src/duid.h
  • src/if-bsd.c
  • src/if-linux-wext.c
  • src/if-linux.c
  • src/if-options.c
  • src/if-options.h
  • src/if-sun.c
  • src/if.c
  • src/if.h
  • src/ipv4.c
  • src/ipv4.h
  • src/ipv4ll.c
  • src/ipv4ll.h
  • src/ipv6.c
  • src/ipv6.h
  • src/ipv6nd.c
  • src/ipv6nd.h
  • src/logerr.c
  • src/logerr.h
  • src/privsep-bpf.c
  • src/privsep-bpf.h
  • src/privsep-bsd.c
  • src/privsep-control.c
  • src/privsep-control.h
  • src/privsep-inet.c
  • src/privsep-linux.c
  • src/privsep-root.c
  • src/privsep-root.h
  • src/privsep-sun.c
  • src/privsep.c
  • src/privsep.h
  • src/queue.h
  • src/route.c
  • src/route.h
  • src/sa.c
  • src/sa.h
  • src/script.c
  • src/script.h

Comment thread .clangd Outdated
Comment thread .github/workflows/format.yml Outdated
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In @.github/workflows/build.yml:
- Around line 31-113: Uncomment and restore the openbsd, freebsd, and netbsd
jobs in the GitHub Actions workflow so BSD CI runs again, but make them
non-blocking by adding continue-on-error: true to each job block (openbsd,
freebsd, netbsd) or alternatively move them into a separate scheduled/manual
workflow; after doing this remove the large commented blocks and ensure the
existing job steps (Bootstrap, Install Dependencies, Build, Tests) remain
unchanged so the matrix/steps still execute.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 4c20f046-ec4e-4bce-a544-3f4fbc00be99

📥 Commits

Reviewing files that changed from the base of the PR and between 2bccd05 and 0001a26.

📒 Files selected for processing (5)
  • .clangd
  • .github/workflows/build.yml
  • .github/workflows/format.yml
  • src/Makefile.inc
  • src/dev/Makefile
✅ Files skipped from review due to trivial changes (3)
  • src/Makefile.inc
  • .github/workflows/format.yml
  • .clangd

Comment on lines +31 to +113
# Sadly the BSDs have stopped building ....

# openbsd:
# runs-on: ubuntu-latest
# steps:
# - name: Bootstrap OpenBSD-latest
# uses: mario-campos/emulate@v1
# with:
# operating-system: openbsd-latest

# - name: Install Dependencies
# run: pkg_add git

# - name: Build
# run: |
# git clone --depth=1 "${{ github.server_url }}/${{ github.repository }}" build
# cd build
# [ "${{ github.event.pull_request.number }}" = "" ] || (echo "fetching PR ${{ github.event.pull_request.number }}"; git fetch origin pull/${{ github.event.pull_request.number }}/head:pr-${{ github.event.pull_request.number }} && git checkout "pr-${{ github.event.pull_request.number }}")
# ./configure
# make

# - name: Tests
# run: |
# ulimit -n 1024
# cd build
# make tests

# freebsd:
# runs-on: ubuntu-latest
# steps:
# - name: Bootstrap FreeBSD-latest
# uses: mario-campos/emulate@v1
# with:
# operating-system: freebsd-latest

# - name: Install Dependencies
# run: pkg install -y git

# - name: Build
# run: |
# git clone --depth=1 "${{ github.server_url }}/${{ github.repository }}" build
# cd build
# [ "${{ github.event.pull_request.number }}" = "" ] || (echo "fetching PR ${{ github.event.pull_request.number }}"; git fetch origin pull/${{ github.event.pull_request.number }}/head:pr-${{ github.event.pull_request.number }} && git checkout "pr-${{ github.event.pull_request.number }}")
# ./configure
# make

# - name: Tests
# run: |
# cd build
# make tests

# netbsd:
# strategy:
# matrix:
# args:
# -
# - --disable-ipv4
# - --disable-arp
# - --disable-ipv4ll
# - --disable-ipv6
# - --disable-dhcp6
# cppflags:
# -
# - -DSMALL
# runs-on: ubuntu-latest
# steps:
# - name: Bootstrap NetBSD-latest
# uses: mario-campos/emulate@v1
# with:
# operating-system: netbsd-latest

# - name: Build
# run: |
# git clone --depth=1 "${{ github.server_url }}/${{ github.repository }}" build
# cd build
# [ "${{ github.event.pull_request.number }}" = "" ] || (echo "fetching PR ${{ github.event.pull_request.number }}"; git fetch origin pull/${{ github.event.pull_request.number }}/head:pr-${{ github.event.pull_request.number }} && git checkout "pr-${{ github.event.pull_request.number }}")
# CFLAGS=-Werror CPPFLAGS="${{ matrix.cppflags }}" ./configure ${{ matrix.args }}
# make

# - name: Tests
# run: |
# cd build
# make tests
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Re-enable BSD CI as non-blocking instead of fully commenting it out.

Commenting out openbsd, freebsd, and netbsd removes all BSD regression signal; from this point, BSD breakage can merge unnoticed. Keep these jobs runnable but non-blocking (continue-on-error: true) and/or move them to a scheduled/manual workflow if they’re currently flaky.

Suggested direction
+  openbsd:
+    continue-on-error: true
+    if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch'
+    runs-on: ubuntu-latest
+    steps:
+      # existing steps...

Apply the same pattern to freebsd and netbsd, and remove the large commented blocks once moved.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.github/workflows/build.yml around lines 31 - 113, Uncomment and restore the
openbsd, freebsd, and netbsd jobs in the GitHub Actions workflow so BSD CI runs
again, but make them non-blocking by adding continue-on-error: true to each job
block (openbsd, freebsd, netbsd) or alternatively move them into a separate
scheduled/manual workflow; after doing this remove the large commented blocks
and ensure the existing job steps (Bootstrap, Install Dependencies, Build,
Tests) remain unchanged so the matrix/steps still execute.

@rsmarples rsmarples merged commit 52faca1 into master Apr 30, 2026
5 checks passed
@rsmarples rsmarples deleted the clang-format branch April 30, 2026 16:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant