]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Be more careful about int vs. Oid in ecpglib.
authorTom Lane <tgl@sss.pgh.pa.us>
Sun, 15 Mar 2026 22:55:37 +0000 (18:55 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Sun, 15 Mar 2026 22:55:46 +0000 (18:55 -0400)
Print an OID value inserted into a SQL query with %u not %d.
The existing code accidentally fails to malfunction when
given an OID above 2^31, but only accidentally; future changes
to our SQL parser could perhaps break it.

Declare the Oid values that ecpg_type_infocache_push() and
ecpg_is_type_an_array() work with as "Oid" not "int".
This doesn't have any functional effect, but it's clearer.

At the moment I don't see a need to back-patch this.

Bug: #19429
Author: fairyfar@msn.com
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/19429-aead3b1874be1a99@postgresql.org

src/interfaces/ecpg/ecpglib/ecpglib_extern.h
src/interfaces/ecpg/ecpglib/execute.c

index 949ff66cefc9291f6a9f260640a12c8c6c141a9e..bea1398fce8799f869f68caa984b2934d2e54bc9 100644 (file)
@@ -52,7 +52,7 @@ struct ECPGgeneric_bytea
 struct ECPGtype_information_cache
 {
        struct ECPGtype_information_cache *next;
-       int                     oid;
+       Oid                     oid;
        enum ARRAY_TYPE isarray;
 };
 
index bd10fef5748dc6ccc14ca26ac5ef1b79b392dad2..ba41732dec6f484c85d057a906fdf8718cca555d 100644 (file)
@@ -145,7 +145,7 @@ next_insert(char *text, int pos, bool questionmarks, bool std_strings)
 }
 
 static bool
-ecpg_type_infocache_push(struct ECPGtype_information_cache **cache, int oid, enum ARRAY_TYPE isarray, int lineno)
+ecpg_type_infocache_push(struct ECPGtype_information_cache **cache, Oid oid, enum ARRAY_TYPE isarray, int lineno)
 {
        struct ECPGtype_information_cache *new_entry
        = (struct ECPGtype_information_cache *) ecpg_alloc(sizeof(struct ECPGtype_information_cache), lineno);
@@ -161,7 +161,7 @@ ecpg_type_infocache_push(struct ECPGtype_information_cache **cache, int oid, enu
 }
 
 static enum ARRAY_TYPE
-ecpg_is_type_an_array(int type, const struct statement *stmt, const struct variable *var)
+ecpg_is_type_an_array(Oid type, const struct statement *stmt, const struct variable *var)
 {
        char       *array_query;
        enum ARRAY_TYPE isarray = ECPG_ARRAY_NOT_SET;
@@ -267,7 +267,7 @@ ecpg_is_type_an_array(int type, const struct statement *stmt, const struct varia
        if (array_query == NULL)
                return ECPG_ARRAY_ERROR;
 
-       sprintf(array_query, "select typlen from pg_type where oid=%d and typelem<>0", type);
+       sprintf(array_query, "select typlen from pg_type where oid=%u and typelem<>0", type);
        query = PQexec(stmt->connection->connection, array_query);
        ecpg_free(array_query);
        if (!ecpg_check_PQresult(query, stmt->lineno, stmt->connection->connection, stmt->compat))
@@ -294,7 +294,8 @@ ecpg_is_type_an_array(int type, const struct statement *stmt, const struct varia
                return ECPG_ARRAY_ERROR;
 
        ecpg_type_infocache_push(&(stmt->connection->cache_head), type, isarray, stmt->lineno);
-       ecpg_log("ecpg_is_type_an_array on line %d: type (%d); C (%d); array (%s)\n", stmt->lineno, type, var->type, ECPG_IS_ARRAY(isarray) ? "yes" : "no");
+       ecpg_log("ecpg_is_type_an_array on line %d: type (%u); C (%d); array (%s)\n",
+                        stmt->lineno, type, var->type, ECPG_IS_ARRAY(isarray) ? "yes" : "no");
        return isarray;
 }