From fbb2e9a030ee7a3fa20ce402e4b1da9809b4eb52 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Wed, 2 May 2018 15:52:54 -0400 Subject: [PATCH] Fix assorted compiler warnings seen in the buildfarm. Failure to use DatumGetFoo/FooGetDatum macros correctly, or at all, causes some warnings about sign conversion. This is just cosmetic at the moment but in principle it's a type violation, so clean up the instances I could find. autoprewarm.c and sharedfileset.c contained code that unportably assumed that pid_t is the same size as int. We've variously dealt with this by casting pid_t to int or to unsigned long for printing purposes; I went with the latter. Fix uninitialized-variable warning in RestoreGUCState. This is a live bug in some sense, but of no great significance given that nobody is very likely to care what "line number" is associated with a GUC that hasn't got a source file recorded. --- contrib/hstore/hstore_io.c | 10 +++++++--- contrib/jsonb_plpython/jsonb_plpython.c | 9 +++++++-- contrib/pg_prewarm/autoprewarm.c | 20 ++++++++++---------- src/backend/storage/file/sharedfileset.c | 4 ++-- src/backend/utils/adt/jsonb.c | 19 +++++++++++++------ src/backend/utils/adt/numeric.c | 24 ++++++++++++------------ src/backend/utils/adt/pgstatfuncs.c | 2 +- src/backend/utils/misc/guc.c | 2 ++ 8 files changed, 54 insertions(+), 36 deletions(-) diff --git a/contrib/hstore/hstore_io.c b/contrib/hstore/hstore_io.c index 7a741a779c..745497c76f 100644 --- a/contrib/hstore/hstore_io.c +++ b/contrib/hstore/hstore_io.c @@ -1462,10 +1462,14 @@ hstore_to_jsonb_loose(PG_FUNCTION_ARGS) HSTORE_VALLEN(entries, i)); if (IsValidJsonNumber(tmp.data, tmp.len)) { + Datum numd; + val.type = jbvNumeric; - val.val.numeric = DatumGetNumeric( - DirectFunctionCall3(numeric_in, - CStringGetDatum(tmp.data), 0, -1)); + numd = DirectFunctionCall3(numeric_in, + CStringGetDatum(tmp.data), + ObjectIdGetDatum(InvalidOid), + Int32GetDatum(-1)); + val.val.numeric = DatumGetNumeric(numd); } else { diff --git a/contrib/jsonb_plpython/jsonb_plpython.c b/contrib/jsonb_plpython/jsonb_plpython.c index 08a7598aae..645238f15b 100644 --- a/contrib/jsonb_plpython/jsonb_plpython.c +++ b/contrib/jsonb_plpython/jsonb_plpython.c @@ -325,8 +325,13 @@ PLyNumber_ToJsonbValue(PyObject *obj, JsonbValue *jbvNum) PG_TRY(); { - num = DatumGetNumeric(DirectFunctionCall3(numeric_in, - CStringGetDatum(str), 0, -1)); + Datum numd; + + numd = DirectFunctionCall3(numeric_in, + CStringGetDatum(str), + ObjectIdGetDatum(InvalidOid), + Int32GetDatum(-1)); + num = DatumGetNumeric(numd); } PG_CATCH(); { diff --git a/contrib/pg_prewarm/autoprewarm.c b/contrib/pg_prewarm/autoprewarm.c index bb28e237d1..9faabe576d 100644 --- a/contrib/pg_prewarm/autoprewarm.c +++ b/contrib/pg_prewarm/autoprewarm.c @@ -180,8 +180,8 @@ autoprewarm_main(Datum main_arg) { LWLockRelease(&apw_state->lock); ereport(LOG, - (errmsg("autoprewarm worker is already running under PID %d", - apw_state->bgworker_pid))); + (errmsg("autoprewarm worker is already running under PID %lu", + (unsigned long) apw_state->bgworker_pid))); return; } apw_state->bgworker_pid = MyProcPid; @@ -290,8 +290,8 @@ apw_load_buffers(void) { LWLockRelease(&apw_state->lock); ereport(LOG, - (errmsg("skipping prewarm because block dump file is being written by PID %d", - apw_state->pid_using_dumpfile))); + (errmsg("skipping prewarm because block dump file is being written by PID %lu", + (unsigned long) apw_state->pid_using_dumpfile))); return; } LWLockRelease(&apw_state->lock); @@ -580,12 +580,12 @@ apw_dump_now(bool is_bgworker, bool dump_unlogged) { if (!is_bgworker) ereport(ERROR, - (errmsg("could not perform block dump because dump file is being used by PID %d", - apw_state->pid_using_dumpfile))); + (errmsg("could not perform block dump because dump file is being used by PID %lu", + (unsigned long) apw_state->pid_using_dumpfile))); ereport(LOG, - (errmsg("skipping block dump because it is already being performed by PID %d", - apw_state->pid_using_dumpfile))); + (errmsg("skipping block dump because it is already being performed by PID %lu", + (unsigned long) apw_state->pid_using_dumpfile))); return 0; } @@ -717,8 +717,8 @@ autoprewarm_start_worker(PG_FUNCTION_ARGS) if (pid != InvalidPid) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), - errmsg("autoprewarm worker is already running under PID %d", - pid))); + errmsg("autoprewarm worker is already running under PID %lu", + (unsigned long) pid))); apw_start_master_worker(); diff --git a/src/backend/storage/file/sharedfileset.c b/src/backend/storage/file/sharedfileset.c index 0ac8696536..d41b39a177 100644 --- a/src/backend/storage/file/sharedfileset.c +++ b/src/backend/storage/file/sharedfileset.c @@ -214,9 +214,9 @@ SharedFileSetPath(char *path, SharedFileSet *fileset, Oid tablespace) char tempdirpath[MAXPGPATH]; TempTablespacePath(tempdirpath, tablespace); - snprintf(path, MAXPGPATH, "%s/%s%d.%u.sharedfileset", + snprintf(path, MAXPGPATH, "%s/%s%lu.%u.sharedfileset", tempdirpath, PG_TEMP_FILE_PREFIX, - fileset->creator_pid, fileset->number); + (unsigned long) fileset->creator_pid, fileset->number); } /* diff --git a/src/backend/utils/adt/jsonb.c b/src/backend/utils/adt/jsonb.c index e99bbc482a..9d2b89f90c 100644 --- a/src/backend/utils/adt/jsonb.c +++ b/src/backend/utils/adt/jsonb.c @@ -343,6 +343,7 @@ jsonb_in_scalar(void *pstate, char *token, JsonTokenType tokentype) { JsonbInState *_state = (JsonbInState *) pstate; JsonbValue v; + Datum numd; switch (tokentype) { @@ -361,18 +362,19 @@ jsonb_in_scalar(void *pstate, char *token, JsonTokenType tokentype) */ Assert(token != NULL); v.type = jbvNumeric; - v.val.numeric = DatumGetNumeric(DirectFunctionCall3(numeric_in, CStringGetDatum(token), 0, -1)); - + numd = DirectFunctionCall3(numeric_in, + CStringGetDatum(token), + ObjectIdGetDatum(InvalidOid), + Int32GetDatum(-1)); + v.val.numeric = DatumGetNumeric(numd); break; case JSON_TOKEN_TRUE: v.type = jbvBool; v.val.boolean = true; - break; case JSON_TOKEN_FALSE: v.type = jbvBool; v.val.boolean = false; - break; case JSON_TOKEN_NULL: v.type = jbvNull; @@ -772,9 +774,14 @@ datum_to_jsonb(Datum val, bool is_null, JsonbInState *result, strchr(outputstr, 'n') != NULL); if (!numeric_error) { - jb.type = jbvNumeric; - jb.val.numeric = DatumGetNumeric(DirectFunctionCall3(numeric_in, CStringGetDatum(outputstr), 0, -1)); + Datum numd; + jb.type = jbvNumeric; + numd = DirectFunctionCall3(numeric_in, + CStringGetDatum(outputstr), + ObjectIdGetDatum(InvalidOid), + Int32GetDatum(-1)); + jb.val.numeric = DatumGetNumeric(numd); pfree(outputstr); } else diff --git a/src/backend/utils/adt/numeric.c b/src/backend/utils/adt/numeric.c index c56d5afcb3..dcf31e340c 100644 --- a/src/backend/utils/adt/numeric.c +++ b/src/backend/utils/adt/numeric.c @@ -3818,8 +3818,8 @@ numeric_avg_deserialize(PG_FUNCTION_ARGS) /* sumX */ temp = DirectFunctionCall3(numeric_recv, PointerGetDatum(&buf), - InvalidOid, - -1); + ObjectIdGetDatum(InvalidOid), + Int32GetDatum(-1)); init_var_from_num(DatumGetNumeric(temp), &tmp_var); accum_sum_add(&(result->sumX), &tmp_var); @@ -3941,16 +3941,16 @@ numeric_deserialize(PG_FUNCTION_ARGS) /* sumX */ temp = DirectFunctionCall3(numeric_recv, PointerGetDatum(&buf), - InvalidOid, - -1); + ObjectIdGetDatum(InvalidOid), + Int32GetDatum(-1)); init_var_from_num(DatumGetNumeric(temp), &sumX_var); accum_sum_add(&(result->sumX), &sumX_var); /* sumX2 */ temp = DirectFunctionCall3(numeric_recv, PointerGetDatum(&buf), - InvalidOid, - -1); + ObjectIdGetDatum(InvalidOid), + Int32GetDatum(-1)); init_var_from_num(DatumGetNumeric(temp), &sumX2_var); accum_sum_add(&(result->sumX2), &sumX2_var); @@ -4340,14 +4340,14 @@ numeric_poly_deserialize(PG_FUNCTION_ARGS) /* sumX */ sumX = DirectFunctionCall3(numeric_recv, PointerGetDatum(&buf), - InvalidOid, - -1); + ObjectIdGetDatum(InvalidOid), + Int32GetDatum(-1)); /* sumX2 */ sumX2 = DirectFunctionCall3(numeric_recv, PointerGetDatum(&buf), - InvalidOid, - -1); + ObjectIdGetDatum(InvalidOid), + Int32GetDatum(-1)); init_var_from_num(DatumGetNumeric(sumX), &sumX_var); #ifdef HAVE_INT128 @@ -4550,8 +4550,8 @@ int8_avg_deserialize(PG_FUNCTION_ARGS) /* sumX */ temp = DirectFunctionCall3(numeric_recv, PointerGetDatum(&buf), - InvalidOid, - -1); + ObjectIdGetDatum(InvalidOid), + Int32GetDatum(-1)); init_var_from_num(DatumGetNumeric(temp), &num); #ifdef HAVE_INT128 numericvar_to_int128(&num, &result->sumX); diff --git a/src/backend/utils/adt/pgstatfuncs.c b/src/backend/utils/adt/pgstatfuncs.c index 6110e40d3e..e95e347184 100644 --- a/src/backend/utils/adt/pgstatfuncs.c +++ b/src/backend/utils/adt/pgstatfuncs.c @@ -813,7 +813,7 @@ pg_stat_get_activity(PG_FUNCTION_ARGS) */ nulls[12] = true; nulls[13] = true; - values[14] = DatumGetInt32(-1); + values[14] = Int32GetDatum(-1); } else { diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c index e1c51c5481..f496ad6281 100644 --- a/src/backend/utils/misc/guc.c +++ b/src/backend/utils/misc/guc.c @@ -9610,6 +9610,8 @@ RestoreGUCState(void *gucstate) if (varsourcefile[0]) read_gucstate_binary(&srcptr, srcend, &varsourceline, sizeof(varsourceline)); + else + varsourceline = 0; read_gucstate_binary(&srcptr, srcend, &varsource, sizeof(varsource)); read_gucstate_binary(&srcptr, srcend, -- 2.40.0