Unnecessary pointer-NULL checks in pgp-pgsql.c - Mailing list pgsql-hackers

From Michael Paquier
Subject Unnecessary pointer-NULL checks in pgp-pgsql.c
Date
Msg-id CAB7nPqRE25Xi15A-dpS4OW7VCNyyf0F3OWBNc0CSCLd_KM5G9Q@mail.gmail.com
Whole thread Raw
Responses Re: Unnecessary pointer-NULL checks in pgp-pgsql.c  (Robert Haas <robertmhaas@gmail.com>)
List pgsql-hackers
Hi all,

Coverity is pointing out that we are doing pointer-NULL checks on
things that cannot be NULL in decrypt_internal():
 out:
-       if (src)
-               mbuf_free(src);
-       if (ctx)
-               pgp_free(ctx);
+       Assert(ctx != NULL && src != NULL && dst != NULL);
+       mbuf_free(src);
+       pgp_free(ctx);

        if (err)
        {
                px_set_debug_handler(NULL);
-               if (dst)
-                       mbuf_free(dst);
+               mbuf_free(dst);

src, dst and ctx are created respectively from mbuf_create_from_data,
mbuf_create and pgp_init which never return NULL and they are palloc'd
all the time. I think that we could simplify things with the patch
attached, note that I added an assertion for correctness but I don't
really think that it is much necessary.
Regards,
--
Michael

Attachment

pgsql-hackers by date:

Previous
From: Michael Paquier
Date:
Subject: Some dead code in metaphone() of fuzzystrmatch.c
Next
From: Amit Kapila
Date:
Subject: Re: WIP: dynahash replacement for buffer table