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

Commitb196b7f

Browse files
committed
Get rid of dependency on strtoull() --- Marko Kreen.
Some additional minor editorializing by Tom.
1 parent7121cc9 commitb196b7f

File tree

3 files changed

+59
-13
lines changed

3 files changed

+59
-13
lines changed

‎contrib/txid/expected/txid.out

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,18 @@ select '12:13:'::txid_snapshot;
88
(1 row)
99

1010
select '12:13:1,2'::txid_snapshot;
11-
ERROR:illegal txid_snapshotinputformat
11+
ERROR:invalidinputfor txid_snapshot: "12:13:1,2"
1212
-- errors
1313
select '31:12:'::txid_snapshot;
14-
ERROR:illegal txid_snapshotinputformat
14+
ERROR:invalidinputfor txid_snapshot: "31:12:"
1515
select '0:1:'::txid_snapshot;
16-
ERROR:illegal txid_snapshotinputformat
16+
ERROR:invalidinputfor txid_snapshot: "0:1:"
1717
select '12:13:0'::txid_snapshot;
18-
ERROR:illegal txid_snapshotinputformat
18+
ERROR:invalidinputfor txid_snapshot: "12:13:0"
1919
select '12:16:14,13'::txid_snapshot;
20-
ERROR:illegal txid_snapshotinputformat
20+
ERROR:invalidinputfor txid_snapshot: "12:16:14,13"
2121
select '12:16:14,14'::txid_snapshot;
22-
ERROR:illegal txid_snapshotinputformat
22+
ERROR:invalidinputfor txid_snapshot: "12:16:14,14"
2323
create table snapshot_test (
2424
nrinteger,
2525
snaptxid_snapshot
@@ -210,3 +210,12 @@ select txid_visible_in_snapshot('1000100010001015', '1000100010001000:1000100010
210210
t
211211
(1 row)
212212

213+
-- test 64bit overflow
214+
SELECT txid_snapshot '1:9223372036854775807:3';
215+
txid_snapshot
216+
-------------------------
217+
1:9223372036854775807:3
218+
(1 row)
219+
220+
SELECT txid_snapshot '1:9223372036854775808:3';
221+
ERROR: invalid input for txid_snapshot: "1:9223372036854775808:3"

‎contrib/txid/sql/txid.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,6 @@ select txid_snapshot '1000100010001000:1000100010001100:1000100010001012,1000100
5656
select txid_visible_in_snapshot('1000100010001012','1000100010001000:1000100010001100:1000100010001012,1000100010001013');
5757
select txid_visible_in_snapshot('1000100010001015','1000100010001000:1000100010001100:1000100010001012,1000100010001013');
5858

59+
-- test 64bit overflow
60+
SELECT txid_snapshot'1:9223372036854775807:3';
61+
SELECT txid_snapshot'1:9223372036854775808:3';

‎contrib/txid/txid.c

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,39 @@ buf_finalize(StringInfo buf)
225225
returnsnap;
226226
}
227227

228+
/*
229+
* simple number parser.
230+
*
231+
* We return 0 on error, which is invalid value for txid.
232+
*/
233+
statictxid
234+
str2txid(constchar*s,constchar**endp)
235+
{
236+
txidval=0;
237+
238+
for (;*s;s++)
239+
{
240+
txidlast=val;
241+
242+
if (*s<'0'||*s>'9')
243+
break;
244+
245+
val=val*10+ (*s-'0');
246+
247+
/*
248+
* check for overflow
249+
*/
250+
if (val>MAX_TXID|| (val /10)!=last)
251+
{
252+
val=0;
253+
break;
254+
}
255+
}
256+
if (endp)
257+
*endp=s;
258+
returnval;
259+
}
260+
228261
/*
229262
* parse snapshot from cstring
230263
*/
@@ -234,21 +267,22 @@ parse_snapshot(const char *str)
234267
txidxmin;
235268
txidxmax;
236269
txidlast_val=0,val;
237-
char*endp;
270+
constchar*str_start=str;
271+
constchar*endp;
238272
StringInfobuf;
239273

240-
xmin=(txid)strtoull(str,&endp,0);
274+
xmin=str2txid(str,&endp);
241275
if (*endp!=':')
242276
gotobad_format;
243277
str=endp+1;
244278

245-
xmax=(txid)strtoull(str,&endp,0);
279+
xmax=str2txid(str,&endp);
246280
if (*endp!=':')
247281
gotobad_format;
248282
str=endp+1;
249283

250284
/* it should look sane */
251-
if (xmin>xmax||xmin==0||xmax>MAX_TXID)
285+
if (xmin==0||xmax==0||xmin>xmax)
252286
gotobad_format;
253287

254288
/* allocate buffer */
@@ -258,11 +292,11 @@ parse_snapshot(const char *str)
258292
while (*str!='\0')
259293
{
260294
/* read next value */
261-
val=(txid)strtoull(str,&endp,0);
295+
val=str2txid(str,&endp);
262296
str=endp;
263297

264298
/* require the input to be in order */
265-
if (val<xmin||val<=last_val||val>=xmax)
299+
if (val<xmin||val>=xmax||val<=last_val)
266300
gotobad_format;
267301

268302
buf_add_txid(buf,val);
@@ -277,7 +311,7 @@ parse_snapshot(const char *str)
277311
returnbuf_finalize(buf);
278312

279313
bad_format:
280-
elog(ERROR,"illegal txid_snapshotinputformat");
314+
elog(ERROR,"invalidinputfor txid_snapshot: \"%s\"",str_start);
281315
returnNULL;
282316
}
283317

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp