diff --git a/src/backend/utils/adt/xid.c b/src/backend/utils/adt/xid.c index 9db5814219..1dad5407f9 100644 --- a/src/backend/utils/adt/xid.c +++ b/src/backend/utils/adt/xid.c @@ -41,13 +41,10 @@ Datum xidout(PG_FUNCTION_ARGS) { TransactionId transactionId = PG_GETARG_TRANSACTIONID(0); + char *result = (char *) palloc(16); - /* maximum 32 bit unsigned integer representation takes 10 chars */ - char *str = palloc(11); - - snprintf(str, 11, "%lu", (unsigned long) transactionId); - - PG_RETURN_CSTRING(str); + snprintf(result, 16, "%lu", (unsigned long) transactionId); + PG_RETURN_CSTRING(result); } /* @@ -160,12 +157,9 @@ xidComparator(const void *arg1, const void *arg2) Datum cidin(PG_FUNCTION_ARGS) { - char *s = PG_GETARG_CSTRING(0); - CommandId c; + char *str = PG_GETARG_CSTRING(0); - c = atoi(s); - - PG_RETURN_COMMANDID(c); + PG_RETURN_COMMANDID((CommandId) strtoul(str, NULL, 0)); } /* @@ -177,7 +171,7 @@ cidout(PG_FUNCTION_ARGS) CommandId c = PG_GETARG_COMMANDID(0); char *result = (char *) palloc(16); - snprintf(result, 16, "%u", (unsigned int) c); + snprintf(result, 16, "%lu", (unsigned long) c); PG_RETURN_CSTRING(result); }