diff options
Diffstat (limited to 'src/backend/utils/adt/tid.c')
-rw-r--r-- | src/backend/utils/adt/tid.c | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/src/backend/utils/adt/tid.c b/src/backend/utils/adt/tid.c index 598e0d8a3b1..e81248a6db0 100644 --- a/src/backend/utils/adt/tid.c +++ b/src/backend/utils/adt/tid.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/tid.c,v 1.31 2002/06/20 20:29:38 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/tid.c,v 1.32 2002/07/16 17:55:25 momjian Exp $ * * NOTES * input routine largely stolen from boxin(). @@ -18,6 +18,10 @@ #include "postgres.h" +#include <errno.h> +#include <math.h> +#include <limits.h> + #include "access/heapam.h" #include "catalog/namespace.h" #include "utils/builtins.h" @@ -47,6 +51,8 @@ tidin(PG_FUNCTION_ARGS) ItemPointer result; BlockNumber blockNumber; OffsetNumber offsetNumber; + char *badp; + int hold_offset; for (i = 0, p = str; *p && i < NTIDARGS && *p != RDELIM; p++) if (*p == DELIM || (*p == LDELIM && !i)) @@ -55,8 +61,16 @@ tidin(PG_FUNCTION_ARGS) if (i < NTIDARGS) elog(ERROR, "invalid tid format: '%s'", str); - blockNumber = (BlockNumber) atoi(coord[0]); - offsetNumber = (OffsetNumber) atoi(coord[1]); + errno = 0; + blockNumber = strtoul(coord[0], &badp, 10); + if (errno || *badp != DELIM) + elog(ERROR, "tidin: invalid value."); + + hold_offset = strtol(coord[1], &badp, 10); + if (errno || *badp != RDELIM || + hold_offset > USHRT_MAX || hold_offset < 0) + elog(ERROR, "tidin: invalid value."); + offsetNumber = hold_offset; result = (ItemPointer) palloc(sizeof(ItemPointerData)); @@ -87,7 +101,7 @@ tidout(PG_FUNCTION_ARGS) blockNumber = BlockIdGetBlockNumber(blockId); offsetNumber = itemPtr->ip_posid; - sprintf(buf, "(%d,%d)", (int) blockNumber, (int) offsetNumber); + sprintf(buf, "(%u,%u)", blockNumber, offsetNumber); PG_RETURN_CSTRING(pstrdup(buf)); } |