Commit 7fc2d508 authored by Tom Lane's avatar Tom Lane

Make to_hex() behave portably on negative input values (treat them as

unsigned integers).  Per report from Jim Crate.
parent edc7f146
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/adt/varlena.c,v 1.108 2003/11/30 20:55:09 joe Exp $ * $PostgreSQL: pgsql/src/backend/utils/adt/varlena.c,v 1.109 2003/12/19 04:56:41 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -2230,11 +2230,11 @@ array_to_text(PG_FUNCTION_ARGS) ...@@ -2230,11 +2230,11 @@ array_to_text(PG_FUNCTION_ARGS)
Datum Datum
to_hex32(PG_FUNCTION_ARGS) to_hex32(PG_FUNCTION_ARGS)
{ {
static char digits[] = "0123456789abcdef"; uint32 value = (uint32) PG_GETARG_INT32(0);
char buf[32]; /* bigger than needed, but reasonable */
char *ptr;
text *result_text; text *result_text;
int32 value = PG_GETARG_INT32(0); char *ptr;
const char *digits = "0123456789abcdef";
char buf[32]; /* bigger than needed, but reasonable */
ptr = buf + sizeof(buf) - 1; ptr = buf + sizeof(buf) - 1;
*ptr = '\0'; *ptr = '\0';
...@@ -2256,11 +2256,11 @@ to_hex32(PG_FUNCTION_ARGS) ...@@ -2256,11 +2256,11 @@ to_hex32(PG_FUNCTION_ARGS)
Datum Datum
to_hex64(PG_FUNCTION_ARGS) to_hex64(PG_FUNCTION_ARGS)
{ {
static char digits[] = "0123456789abcdef"; uint64 value = (uint64) PG_GETARG_INT64(0);
char buf[32]; /* bigger than needed, but reasonable */
char *ptr;
text *result_text; text *result_text;
int64 value = PG_GETARG_INT64(0); char *ptr;
const char *digits = "0123456789abcdef";
char buf[32]; /* bigger than needed, but reasonable */
ptr = buf + sizeof(buf) - 1; ptr = buf + sizeof(buf) - 1;
*ptr = '\0'; *ptr = '\0';
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment