Dereferenced pointers checked as NULL in btree_utils_var.c - Mailing list pgsql-hackers

From Michael Paquier
Subject Dereferenced pointers checked as NULL in btree_utils_var.c
Date
Msg-id CAB7nPqSAtqG7f8CYY7FxahfYWqSd3Sy==5RdDfbEf+MBfhJQmQ@mail.gmail.com
Whole thread Raw
Responses Re: Dereferenced pointers checked as NULL in btree_utils_var.c
List pgsql-hackers
Hi all,

Coverity is pointing out $subject, with the following stuff in gbt_var_same():
        GBT_VARKEY *t1 = (GBT_VARKEY *) DatumGetPointer(d1);
        GBT_VARKEY *t2 = (GBT_VARKEY *) DatumGetPointer(d2);
        GBT_VARKEY_R r1,
                                r2;

        r1 = gbt_var_key_readable(t1); <= t1 dereferenced
        r2 = gbt_var_key_readable(t2); <= t2 dereferenced

        if (t1 && t2)
                result = ((*tinfo->f_cmp) (r1.lower, r2.lower,
collation) == 0 &&
                                  (*tinfo->f_cmp) (r1.upper, r2.upper,
collation) == 0);
        else
                result = (t1 == NULL && t2 == NULL); <= Coverity complains here

        return result;

As Heikki pointed me out on IM, the lack of crash report in this area,
as well as similar coding style in cube/ seem to be sufficient
arguments to simply remove those NULL checks instead of doing more
solid checks on them. Patch is attached.
Regards,
--
Michael

Attachment

pgsql-hackers by date:

Previous
From: Michael Paquier
Date:
Subject: Re: New CF app deployment
Next
From: Kyotaro HORIGUCHI
Date:
Subject: Re: Async execution of postgres_fdw.