coding: remove unreachable out operand in the Base64 decoders

Premise:  coding.c:177 (Base64_Decode_nonCT) and coding.c:298 (Base64_Decode)
          both open with
            if ((in == NULL && inLen > 0) || out == NULL || outLen == NULL)
                return BAD_FUNC_ARG;
          which establishes out != NULL for the rest of each function.
Claim:    coding.c:281 and coding.c:395, `if (out && *outLen > i)` -- the `out`
          operand in both.
Proof:    out is a parameter and is never reassigned in either function; the
          only uses between the entry check and the null-terminator write are
          subscripted stores (out[i]). Reaching :281 / :395 therefore implies
          out != NULL, so the operand is invariantly true and its independence
          pair is unreachable.
Scope:    neither function contains an #if/#ifdef in the span. Base64_Decode_nonCT
          is compiled under !BASE64_NO_TABLE and aliased to Base64_Decode under
          BASE64_NO_TABLE (:404-408); both variants carry the same entry check,
          so the argument holds either way.
Evidence: llvm-cov MC/DC records both conditions' pairs as uncovered
          (reports/coding/GAPS.md rows 281:9:281:27:0 and 395:9:395:27:0).

Deliberately untouched: the textually identical line in DoBase64_Encode
(coding.c:608). There out == NULL is the documented size-query mode
(`getSzOnly = (out == NULL)` at :520, returning LENGTH_ONLY_E), so that operand
is live and load-bearing -- base64_test exercises it.

Compiler cross-check: gcc -O2 emits byte-identical code for this file before
and after this commit -- the optimiser had already folded the removed
condition, independently confirming it was dead.
This commit is contained in:
Daniele Lacamera
2026-07-31 15:37:05 +02:00
parent 00f098e6ed
commit 03e40fdc25
+2 -2
View File
@@ -278,7 +278,7 @@ int Base64_Decode_nonCT(const byte* in, word32 inLen, byte* out, word32* outLen)
}
/* If the output buffer has a room for an extra byte, add a null terminator */
if (out && *outLen > i)
if (*outLen > i)
out[i]= '\0';
/* Note, *outLen won't reflect the optional terminating null. */
@@ -392,7 +392,7 @@ int Base64_Decode(const byte* in, word32 inLen, byte* out, word32* outLen)
}
/* If the output buffer has a room for an extra byte, add a null terminator */
if (out && *outLen > i)
if (*outLen > i)
out[i]= '\0';
/* Note, *outLen won't reflect the optional terminating null. */