Tom Lane wrote:
> Bruce Momjian <[EMAIL PROTECTED]> writes:
> > The only other
> > unusual case I saw was tid outputing block number as %d and not %u.  Is
> > that OK?
> 
> Seems like it should use %u.  The input side might be wrong too.
> 

OK, fixed.  Patch attached.  There was also some confusion in the code
of how strtol returns its end pointer as always non-NULL:
        
        test=> insert into x values ('(1,2)');
        INSERT 16591 1
        test=> insert into x values ('(1000000000,2)');
        INSERT 16592 1
        test=> insert into x values ('(3000000000,2)');
        INSERT 16593 1
        test=> select * from x;
               y        
        ----------------
                  (1,2)
         (1000000000,2)
         (3000000000,2)
        (3 rows)
        
        test=> insert into x values ('(5000000000,2)');
        ERROR:  tidin: invalid value.
        test=> insert into x values ('(3000000000,200000)');
        ERROR:  tidin: invalid value.
        test=> insert into x values ('(3000000000,20000)');
        INSERT 16595 1

> > Also, pg_class.relpages is an int.  We don't have unsigned int columns.
> 
> Yeah.  I had a todo item to look at all the uses of relpages and make
> sure they were being casted to unsigned ...

They all look OK to me.

-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  [EMAIL PROTECTED]               |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026
Index: src/backend/utils/adt/numutils.c
===================================================================
RCS file: /cvsroot/pgsql/src/backend/utils/adt/numutils.c,v
retrieving revision 1.49
diff -c -r1.49 numutils.c
*** src/backend/utils/adt/numutils.c    20 Jun 2002 20:29:38 -0000      1.49
--- src/backend/utils/adt/numutils.c    16 Jul 2002 17:51:06 -0000
***************
*** 46,52 ****
  pg_atoi(char *s, int size, int c)
  {
        long            l = 0;
!       char       *badp = (char *) NULL;
  
        Assert(s);
  
--- 46,52 ----
  pg_atoi(char *s, int size, int c)
  {
        long            l = 0;
!       char       *badp;
  
        Assert(s);
  
***************
*** 71,77 ****
         */
        if (errno && errno != EINVAL)
                elog(ERROR, "pg_atoi: error reading \"%s\": %m", s);
!       if (badp && *badp && (*badp != c))
                elog(ERROR, "pg_atoi: error in \"%s\": can\'t parse \"%s\"", s, badp);
  
        switch (size)
--- 71,77 ----
         */
        if (errno && errno != EINVAL)
                elog(ERROR, "pg_atoi: error reading \"%s\": %m", s);
!       if (*badp && *badp != c)
                elog(ERROR, "pg_atoi: error in \"%s\": can\'t parse \"%s\"", s, badp);
  
        switch (size)
Index: src/backend/utils/adt/tid.c
===================================================================
RCS file: /cvsroot/pgsql/src/backend/utils/adt/tid.c,v
retrieving revision 1.31
diff -c -r1.31 tid.c
*** src/backend/utils/adt/tid.c 20 Jun 2002 20:29:38 -0000      1.31
--- src/backend/utils/adt/tid.c 16 Jul 2002 17:51:06 -0000
***************
*** 18,23 ****
--- 18,27 ----
  
  #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,52 ****
--- 51,58 ----
        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,62 ****
        if (i < NTIDARGS)
                elog(ERROR, "invalid tid format: '%s'", str);
  
!       blockNumber = (BlockNumber) atoi(coord[0]);
!       offsetNumber = (OffsetNumber) atoi(coord[1]);
  
        result = (ItemPointer) palloc(sizeof(ItemPointerData));
  
--- 61,76 ----
        if (i < NTIDARGS)
                elog(ERROR, "invalid tid format: '%s'", str);
  
!       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,93 ****
        blockNumber = BlockIdGetBlockNumber(blockId);
        offsetNumber = itemPtr->ip_posid;
  
!       sprintf(buf, "(%d,%d)", (int) blockNumber, (int) offsetNumber);
  
        PG_RETURN_CSTRING(pstrdup(buf));
  }
--- 101,107 ----
        blockNumber = BlockIdGetBlockNumber(blockId);
        offsetNumber = itemPtr->ip_posid;
  
!       sprintf(buf, "(%u,%u)", blockNumber, offsetNumber);
  
        PG_RETURN_CSTRING(pstrdup(buf));
  }

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/users-lounge/docs/faq.html

Reply via email to