Fix tid to in/out as unsigned.
This commit is contained in:
parent
14f1588356
commit
7aee5ed3b7
|
@ -11,7 +11,7 @@
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/backend/utils/adt/numutils.c,v 1.49 2002/06/20 20:29:38 momjian Exp $
|
* $Header: /cvsroot/pgsql/src/backend/utils/adt/numutils.c,v 1.50 2002/07/16 17:55:25 momjian Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
@ -46,7 +46,7 @@ int32
|
||||||
pg_atoi(char *s, int size, int c)
|
pg_atoi(char *s, int size, int c)
|
||||||
{
|
{
|
||||||
long l = 0;
|
long l = 0;
|
||||||
char *badp = (char *) NULL;
|
char *badp;
|
||||||
|
|
||||||
Assert(s);
|
Assert(s);
|
||||||
|
|
||||||
|
@ -71,7 +71,7 @@ pg_atoi(char *s, int size, int c)
|
||||||
*/
|
*/
|
||||||
if (errno && errno != EINVAL)
|
if (errno && errno != EINVAL)
|
||||||
elog(ERROR, "pg_atoi: error reading \"%s\": %m", s);
|
elog(ERROR, "pg_atoi: error reading \"%s\": %m", s);
|
||||||
if (badp && *badp && (*badp != c))
|
if (*badp && *badp != c)
|
||||||
elog(ERROR, "pg_atoi: error in \"%s\": can\'t parse \"%s\"", s, badp);
|
elog(ERROR, "pg_atoi: error in \"%s\": can\'t parse \"%s\"", s, badp);
|
||||||
|
|
||||||
switch (size)
|
switch (size)
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* 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
|
* NOTES
|
||||||
* input routine largely stolen from boxin().
|
* input routine largely stolen from boxin().
|
||||||
|
@ -18,6 +18,10 @@
|
||||||
|
|
||||||
#include "postgres.h"
|
#include "postgres.h"
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
#include <math.h>
|
||||||
|
#include <limits.h>
|
||||||
|
|
||||||
#include "access/heapam.h"
|
#include "access/heapam.h"
|
||||||
#include "catalog/namespace.h"
|
#include "catalog/namespace.h"
|
||||||
#include "utils/builtins.h"
|
#include "utils/builtins.h"
|
||||||
|
@ -47,6 +51,8 @@ tidin(PG_FUNCTION_ARGS)
|
||||||
ItemPointer result;
|
ItemPointer result;
|
||||||
BlockNumber blockNumber;
|
BlockNumber blockNumber;
|
||||||
OffsetNumber offsetNumber;
|
OffsetNumber offsetNumber;
|
||||||
|
char *badp;
|
||||||
|
int hold_offset;
|
||||||
|
|
||||||
for (i = 0, p = str; *p && i < NTIDARGS && *p != RDELIM; p++)
|
for (i = 0, p = str; *p && i < NTIDARGS && *p != RDELIM; p++)
|
||||||
if (*p == DELIM || (*p == LDELIM && !i))
|
if (*p == DELIM || (*p == LDELIM && !i))
|
||||||
|
@ -55,8 +61,16 @@ tidin(PG_FUNCTION_ARGS)
|
||||||
if (i < NTIDARGS)
|
if (i < NTIDARGS)
|
||||||
elog(ERROR, "invalid tid format: '%s'", str);
|
elog(ERROR, "invalid tid format: '%s'", str);
|
||||||
|
|
||||||
blockNumber = (BlockNumber) atoi(coord[0]);
|
errno = 0;
|
||||||
offsetNumber = (OffsetNumber) atoi(coord[1]);
|
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));
|
result = (ItemPointer) palloc(sizeof(ItemPointerData));
|
||||||
|
|
||||||
|
@ -87,7 +101,7 @@ tidout(PG_FUNCTION_ARGS)
|
||||||
blockNumber = BlockIdGetBlockNumber(blockId);
|
blockNumber = BlockIdGetBlockNumber(blockId);
|
||||||
offsetNumber = itemPtr->ip_posid;
|
offsetNumber = itemPtr->ip_posid;
|
||||||
|
|
||||||
sprintf(buf, "(%d,%d)", (int) blockNumber, (int) offsetNumber);
|
sprintf(buf, "(%u,%u)", blockNumber, offsetNumber);
|
||||||
|
|
||||||
PG_RETURN_CSTRING(pstrdup(buf));
|
PG_RETURN_CSTRING(pstrdup(buf));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue