Fix IPv6 symmetric difference and add IPv6 multi-input tests#55
Merged
Conversation
ipset6_diff() reloaded lo/hi for the range that did NOT advance after emitting a partial overlap, clobbering the deliberately-adjusted lo of the surviving range. The common head of that range was then re-emitted, so --diff in IPv6 mode wrongly included addresses present in both sets. Mirror the proven IPv4 algorithm: when one range extends past the other, keep the survivor's adjusted lo and only advance/reload the consumed range. hi1>hi2 implies hi2<IPV6_ADDR_MAX, so the increment cannot overflow and the previous max-guard is unnecessary.
Cover the IPv6 multi-file paths that had little or no coverage: merge, common, exclude, symmetric difference, count-unique (merged) and compare-first. These exercise ipset6_merge (previously unreached), ipset6_diff, ipset6_exclude and ipset6_common across two inputs. 98-ipv6-diff guards the symmetric-difference regression: the common address must not appear in the result.
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Duplication | 0 |
🟢 Coverage 50.00% diff coverage · +2.21% coverage variation
Metric Results Coverage variation ✅ +2.21% coverage variation (-1.00%) Diff coverage ✅ 50.00% diff coverage Coverage variation details
Coverable lines Covered lines Coverage Common ancestor commit (5ed9649) 3310 2235 67.52% Head commit (6b32487) 3304 (-6) 2304 (+69) 69.73% (+2.21%) Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch:
<coverage of head commit> - <coverage of common ancestor commit>Diff coverage details
Coverable lines Covered lines Diff coverage Pull request (#55) 4 2 50.00% Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified:
<covered lines added or modified>/<coverable lines added or modified> * 100%
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes a correctness bug in IPv6
--diff(symmetric difference) and adds tests covering the IPv6 multi-input set operations, which were largely or entirely unexercised.The bug
--diffis documented as symmetric difference — IPs in either set but not both. In IPv6 mode it wrongly included addresses common to both sets:The IPv4 path (
ipset_diff) handles the same case correctly.Root cause
In
ipset6_diff(), when one range extended past the other, the code emitted the partial-overlap prefix, set the surviving range'slotohi_other + 1, advanced the consumed index — and then unconditionally reloadedlo/hifor the range that did not advance, clobbering the adjustedlo. The common head of that range was then re-emitted. Both thehi1>hi2andhi2>hi1branches had the mirror defect.The fix mirrors the IPv4 algorithm: keep the survivor's adjusted
lo, advance/reload only the consumed range. (hi1>hi2implieshi2<IPV6_ADDR_MAX, so the increment can't overflow and the previous max-guard is unnecessary.)Verification
Beyond the new fixed cases, I ran differential/property fuzzing on the IPv6 engine (~25k checks, all passing after the fix):
A△B = (A\\B)∪(B\\A),A∪B = (A∩B)∪(A△B),(A\\B)∩B = ∅;No other correctness issues were found.
Tests added (
tests.d/95–100)Multi-input IPv6 coverage for merge, common, exclude, symmetric difference, count-unique (merged) and compare-first.
98-ipv6-diffspecifically guards against the regression (the common address must not appear in the result).Coverage impact (line coverage)
ipset6_merge.cipset6_diff.cipset6_exclude.cipset6_common.ciprange6_main.cAll 100 CLI tests pass.