Fix out-of-array-bounds compiler warning
authorAlvaro Herrera <alvherre@alvh.no-ip.org>
Tue, 17 Mar 2015 01:35:45 +0000 (22:35 -0300)
committerAlvaro Herrera <alvherre@alvh.no-ip.org>
Tue, 17 Mar 2015 01:35:45 +0000 (22:35 -0300)
Since the array length check is using a post-increment operator, the
compiler complains that there's a potential write to one element beyond
the end of the array.  This is not possible currently: the only path to
this function is through pg_get_object_address(), which already verifies
that the input array is no more than two elements in length.  Still, a
bug is a bug.

No idea why my compiler doesn't complain about this ...

Pointed out by Dead Rasheed and Peter Eisentraut

src/backend/catalog/objectaddress.c

index 46ea09a61188a3c7fe89244d68935b68492e312a..5025a4ee5bcfaa51aa8fc14c5cf6cb7d9b6495da 100644 (file)
@@ -1428,7 +1428,7 @@ get_object_address_opf_member(ObjectType objtype,
        typenames[i] = strVal(lfirst(cell));
        typaddr = get_object_address_type(OBJECT_TYPE, cell, missing_ok);
        typeoids[i] = typaddr.objectId;
-       if (i++ >= 2)
+       if (++i >= 2)
            break;
    }