]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Silence uninitialized value false positives
authorMark Andrews <marka@isc.org>
Wed, 8 Mar 2023 04:16:44 +0000 (15:16 +1100)
committerMark Andrews <marka@isc.org>
Wed, 8 Mar 2023 22:40:03 +0000 (22:40 +0000)
In base32_decode_char the GCC 12 static analyser fails to determine
that ctx->val[1], ctx->val[3], ctx->val[4] and ctx->val[6] are
assigned values by the previous call to base32_decode_char.  Initialise
ctx->val to zeros when initalising the rest of ctx to silence the
false positive.

lib/isc/base32.c

index 90c37c75f62aa940e32111eaff477d26ff320925..ce6db733e44c74f5afc0353fe1e791e64198fc5f 100644 (file)
@@ -149,18 +149,6 @@ typedef struct {
        bool pad;         /*%< Expect padding */
 } base32_decode_ctx_t;
 
-static void
-base32_decode_init(base32_decode_ctx_t *ctx, int length, const char base[],
-                  bool pad, isc_buffer_t *target) {
-       ctx->digits = 0;
-       ctx->seen_end = false;
-       ctx->seen_32 = 0;
-       ctx->length = length;
-       ctx->target = target;
-       ctx->base = base;
-       ctx->pad = pad;
-}
-
 static isc_result_t
 base32_decode_char(base32_decode_ctx_t *ctx, int c) {
        const char *s;
@@ -293,15 +281,15 @@ static isc_result_t
 base32_tobuffer(isc_lex_t *lexer, const char base[], bool pad,
                isc_buffer_t *target, int length) {
        unsigned int before, after;
-       base32_decode_ctx_t ctx;
+       base32_decode_ctx_t ctx = {
+               .length = length, .base = base, .target = target, .pad = pad
+       };
        isc_textregion_t *tr;
        isc_token_t token;
        bool eol;
 
        REQUIRE(length >= -2);
 
-       base32_decode_init(&ctx, length, base, pad, target);
-
        before = isc_buffer_usedlength(target);
        while (!ctx.seen_end && (ctx.length != 0)) {
                unsigned int i;
@@ -350,9 +338,10 @@ isc_base32hexnp_tobuffer(isc_lex_t *lexer, isc_buffer_t *target, int length) {
 static isc_result_t
 base32_decodestring(const char *cstr, const char base[], bool pad,
                    isc_buffer_t *target) {
-       base32_decode_ctx_t ctx;
+       base32_decode_ctx_t ctx = {
+               .length = -1, .base = base, .target = target, .pad = pad
+       };
 
-       base32_decode_init(&ctx, -1, base, pad, target);
        for (;;) {
                int c = *cstr++;
                if (c == '\0') {
@@ -385,9 +374,10 @@ isc_base32hexnp_decodestring(const char *cstr, isc_buffer_t *target) {
 static isc_result_t
 base32_decoderegion(isc_region_t *source, const char base[], bool pad,
                    isc_buffer_t *target) {
-       base32_decode_ctx_t ctx;
+       base32_decode_ctx_t ctx = {
+               .length = -1, .base = base, .target = target, .pad = pad
+       };
 
-       base32_decode_init(&ctx, -1, base, pad, target);
        while (source->length != 0) {
                int c = *source->base;
                RETERR(base32_decode_char(&ctx, c));