Static analysis cleanup: dead code, format string, size_t nits - #426
Merged
thegushi merged 1 commit intoJul 22, 2026
Merged
Conversation
A grab-bag of small cppcheck findings, none independently significant
but worth cleaning up together:
- libvbr/vbr.c, librbl/rbl.c: remove a dead "if (ret == -1) {...} else
{...}" block in the DNS query path. An identical "ret == -1" check
earlier in the same function already returns on that condition, so
the else branch always ran; cppcheck confirms both conditions are
always false.
- libopendkim/dkim-test.c: fix %zd/%zu format string mismatch
(outkey_len and sig_keylen are size_t, not ssize_t) and a "key do
not match" -> "keys do not match" typo to match nearby wording.
- libopendkim/dkim.c, dkim_sign(): dkim_base64_decode() returns int
(-1 on error) but was assigned directly into dkim_keylen, which is
size_t; "dkim_keylen <= 0" never caught the -1 case since it wraps
to SIZE_MAX. Not reachable via opendkim-genkey (always produces PEM),
but a real hazard for any direct libopendkim caller passing a bare
base64-DER key. Now captured in an int local and checked before
assigning into the size_t field.
- libopendkim/dkim.c, dkim_process_set(): initialize "end" in the "t"
and "x" tag validation so it's not left uninitialized on paths where
it's currently only safe because of short-circuit evaluation.
- libopendkim/dkim.c, dkim_getsighdr_d(): simplify a dead "if (!first)"
check in the tag-wrapping loop -- by the time that branch is
reached, "first" is already guaranteed FALSE (the branch above
already handles "len == 0 || first"), so the check and the trailing
reassignment were both no-ops. cppcheck: "Condition '!first' is
always true".
- libopendkim/base32.c, dkim_base32_encode(): remove a redundant
"iin >= size" clause from three of the unrolled loop's bounds
checks, each of which immediately re-tests a value already proven
false by an identical check a few lines above with no intervening
change to "iin". cppcheck: "Condition 'iin>=size' is always false"
(x3).
thegushi
added a commit
that referenced
this pull request
Jul 22, 2026
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
A grab-bag of small cppcheck findings, none independently significant but worth cleaning up together. Split out from #424 and #425, which cover the two higher-priority findings from the same static analysis pass.
if (ret == -1) {...} else {...}block in the DNS query path. An identicalret == -1check earlier in the same function already returns on that condition, so theelsebranch always ran. cppcheck confirms both conditions are always false.%zd/%zuformat string mismatch (outkey_lenandsig_keylenaresize_t, notssize_t) and a "key do not match" -> "keys do not match" typo to match nearby wording.dkim_sign():dkim_base64_decode()returnsint(-1 on error) but was assigned directly intodkim_keylen, which issize_t;dkim_keylen <= 0never caught the -1 case since it wraps toSIZE_MAX. Not reachable viaopendkim-genkey(always produces PEM), but a real hazard for any direct libopendkim caller passing a bare base64-DER key. Now captured in anintlocal and checked before assigning into thesize_tfield.dkim_process_set(): initializeendin the "t" and "x" tag validation so it's not left uninitialized on paths where it's currently only safe because of short-circuit evaluation.dkim_getsighdr_d(): simplify a deadif (!first)check in the tag-wrapping loop -- by the time that branch is reached,firstis already guaranteed FALSE (the branch above already handleslen == 0 || first), so the check and its trailing reassignment were both no-ops. cppcheck:Condition '!first' is always true.dkim_base32_encode(): remove a redundantiin >= sizeclause from three of the unrolled loop's bounds checks, each of which immediately re-tests a value already proven false by an identical check a few lines above with no intervening change toiin. cppcheck:Condition 'iin>=size' is always false(x3).Test plan
autoreconf -fi && ./configure && gmakebuilds cleangmake check: 174/174 tests pass