Skip to content

Remove duplicate/unreachable if()#128

Merged
job merged 1 commit intobgp:mainfrom
robert-scheck:duplicate-if
Mar 15, 2026
Merged

Remove duplicate/unreachable if()#128
job merged 1 commit intobgp:mainfrom
robert-scheck:duplicate-if

Conversation

@robert-scheck
Copy link
Copy Markdown
Contributor

@robert-scheck robert-scheck commented Apr 7, 2025

Situation:

if (*eptr != '\n') { … }
if (errno == ERANGE && asn == ULONG_MAX) { … }
if (asn == 0 || asn >= 4294967295) { … }
if (eptr && *eptr != '\n') { … }

From my understanding the last if() is duplicate/redundant/unreachable, because whenever the last if() evaluates to true, the first if() already evaluated to true before.

In general this was spotted by GitHub CodeQL in my fork on GitHub, but as as "redundant null check due to previous dereference" (because strtoul() never sets *eptr to NULL).

The current code was introduced with commit b481111; the first if() was previously:

if (q[0] == '\0' || *eptr != '\0') { … }

I'm still not really sure why the previous *eptr check was changed from \0 to \n in the commit mentioned above…please cross-check before accepting this pull request.

@job job merged commit 0f1f594 into bgp:main Mar 15, 2026
6 checks passed
@job
Copy link
Copy Markdown
Member

job commented Mar 15, 2026

thank you!

@robert-scheck robert-scheck deleted the duplicate-if branch March 15, 2026 22:36
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.

2 participants