Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7aee5ed

Browse files
committed
Fix tid to in/out as unsigned.
1 parent14f1588 commit7aee5ed

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

‎src/backend/utils/adt/numutils.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*
1212
*
1313
* IDENTIFICATION
14-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/numutils.c,v 1.49 2002/06/20 20:29:38 momjian Exp $
14+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/numutils.c,v 1.50 2002/07/16 17:55:25 momjian Exp $
1515
*
1616
*-------------------------------------------------------------------------
1717
*/
@@ -46,7 +46,7 @@ int32
4646
pg_atoi(char*s,intsize,intc)
4747
{
4848
longl=0;
49-
char*badp= (char*)NULL;
49+
char*badp;
5050

5151
Assert(s);
5252

@@ -71,7 +71,7 @@ pg_atoi(char *s, int size, int c)
7171
*/
7272
if (errno&&errno!=EINVAL)
7373
elog(ERROR,"pg_atoi: error reading \"%s\": %m",s);
74-
if (badp&&*badp&&(*badp!=c))
74+
if (*badp&&*badp!=c)
7575
elog(ERROR,"pg_atoi: error in \"%s\": can\'t parse \"%s\"",s,badp);
7676

7777
switch (size)

‎src/backend/utils/adt/tid.c

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/tid.c,v 1.31 2002/06/20 20:29:38 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/tid.c,v 1.32 2002/07/16 17:55:25 momjian Exp $
1212
*
1313
* NOTES
1414
* input routine largely stolen from boxin().
@@ -18,6 +18,10 @@
1818

1919
#include"postgres.h"
2020

21+
#include<errno.h>
22+
#include<math.h>
23+
#include<limits.h>
24+
2125
#include"access/heapam.h"
2226
#include"catalog/namespace.h"
2327
#include"utils/builtins.h"
@@ -47,6 +51,8 @@ tidin(PG_FUNCTION_ARGS)
4751
ItemPointerresult;
4852
BlockNumberblockNumber;
4953
OffsetNumberoffsetNumber;
54+
char*badp;
55+
inthold_offset;
5056

5157
for (i=0,p=str;*p&&i<NTIDARGS&&*p!=RDELIM;p++)
5258
if (*p==DELIM|| (*p==LDELIM&& !i))
@@ -55,8 +61,16 @@ tidin(PG_FUNCTION_ARGS)
5561
if (i<NTIDARGS)
5662
elog(ERROR,"invalid tid format: '%s'",str);
5763

58-
blockNumber= (BlockNumber)atoi(coord[0]);
59-
offsetNumber= (OffsetNumber)atoi(coord[1]);
64+
errno=0;
65+
blockNumber=strtoul(coord[0],&badp,10);
66+
if (errno||*badp!=DELIM)
67+
elog(ERROR,"tidin: invalid value.");
68+
69+
hold_offset=strtol(coord[1],&badp,10);
70+
if (errno||*badp!=RDELIM||
71+
hold_offset>USHRT_MAX||hold_offset<0)
72+
elog(ERROR,"tidin: invalid value.");
73+
offsetNumber=hold_offset;
6074

6175
result= (ItemPointer)palloc(sizeof(ItemPointerData));
6276

@@ -87,7 +101,7 @@ tidout(PG_FUNCTION_ARGS)
87101
blockNumber=BlockIdGetBlockNumber(blockId);
88102
offsetNumber=itemPtr->ip_posid;
89103

90-
sprintf(buf,"(%d,%d)",(int)blockNumber, (int)offsetNumber);
104+
sprintf(buf,"(%u,%u)",blockNumber,offsetNumber);
91105

92106
PG_RETURN_CSTRING(pstrdup(buf));
93107
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp