]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
plugins: mail-crypt - fix static analysis pedantry
authorPhil Carmody <phil@dovecot.fi>
Tue, 6 Dec 2016 16:14:31 +0000 (18:14 +0200)
committerPhil Carmody <phil@dovecot.fi>
Tue, 6 Dec 2016 16:29:39 +0000 (18:29 +0200)
Clang cannot see that ret is -1, 0, or 1 upon assigment, and therefore
-1 or 0 upon entry into the if block. Therefore it considers ret==0
not to be a tautology if ret!=-1, and thus falsifiable. It concludes
that bad things can later happen.

The easiest way to persuade it otherwise and make it clear to a human
that things are sane is to make the first error check to be for any
negative ret value, which forces the else path to explicitly imply
ret==0, which means that clause can also be removed. Just removing the
ret==0 doesn't make it so clear to the human that there's no third case.

The final change is simply to mimic the ret==-1 to ret<0 change earlier.

clang's error message:

doveadm-mail-crypt.c:290:14: error: variable 'pubid' is used uninitialized whenever '&&' condition is false [-Werror,-Wsometimes-uninitialized]
  } else if (ret == 0 &&
             ^~~~~~~~
doveadm-mail-crypt.c:304:35: note: uninitialized use occurs here
   res->id = p_strdup(_ctx->pool, pubid);
                                  ^~~~~
doveadm-mail-crypt.c:290:14: note: remove the '&&' if its condition is always true
  } else if (ret == 0 &&
             ^~~~~~~~~~~

Signed-off-by: Phil Carmody <phil@dovecot.fi>
src/plugins/mail-crypt/doveadm-mail-crypt.c

index c9671d7ea7c7ef0cde03a10d8064189d468c9595..4ab1b6ab37189cc31ff765f31804a6a87d72c0a4 100644 (file)
@@ -283,12 +283,11 @@ static int mcp_keypair_generate_run(struct doveadm_mail_cmd_context *_ctx,
        if ((ret = mail_crypt_user_get_public_key(user, &user_key,
                                                  &error)) <= 0) {
                struct dcrypt_keypair pair;
-               if (ret == -1) {
+               if (ret < 0) {
                        i_error("mail_crypt_user_get_public_key(%s) failed: %s",
                                user->username,
                                error);
-               } else if (ret == 0 &&
-                          mail_crypt_user_generate_keypair(user, &pair,
+               } else if (mail_crypt_user_generate_keypair(user, &pair,
                                                             &pubid, &error) < 0) {
                        ret = -1;
                        i_error("mail_crypt_user_generate_keypair(%s) failed: %s",
@@ -309,7 +308,7 @@ static int mcp_keypair_generate_run(struct doveadm_mail_cmd_context *_ctx,
                        user_key = pair.pub;
                        dcrypt_key_unref_private(&pair.priv);
                }
-               if (ret == -1) return ret;
+               if (ret < 0) return ret;
        }
 
        if (ret == 1 && ctx->force &&