Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Postgres FD Implementation
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Abuhujair Javed
Postgres FD Implementation
Commits
b196b7fb
Commit
b196b7fb
authored
Oct 08, 2007
by
Tom Lane
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Get rid of dependency on strtoull() --- Marko Kreen.
Some additional minor editorializing by Tom.
parent
7121cc90
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
59 additions
and
13 deletions
+59
-13
contrib/txid/expected/txid.out
contrib/txid/expected/txid.out
+15
-6
contrib/txid/sql/txid.sql
contrib/txid/sql/txid.sql
+3
-0
contrib/txid/txid.c
contrib/txid/txid.c
+41
-7
No files found.
contrib/txid/expected/txid.out
View file @
b196b7fb
...
...
@@ -8,18 +8,18 @@ select '12:13:'::txid_snapshot;
(1 row)
select '12:13:1,2'::txid_snapshot;
ERROR: i
llegal txid_snapshot input format
ERROR: i
nvalid input for txid_snapshot: "12:13:1,2"
-- errors
select '31:12:'::txid_snapshot;
ERROR: i
llegal txid_snapshot input format
ERROR: i
nvalid input for txid_snapshot: "31:12:"
select '0:1:'::txid_snapshot;
ERROR: i
llegal txid_snapshot input format
ERROR: i
nvalid input for txid_snapshot: "0:1:"
select '12:13:0'::txid_snapshot;
ERROR: i
llegal txid_snapshot input format
ERROR: i
nvalid input for txid_snapshot: "12:13:0"
select '12:16:14,13'::txid_snapshot;
ERROR: i
llegal txid_snapshot input format
ERROR: i
nvalid input for txid_snapshot: "12:16:14,13"
select '12:16:14,14'::txid_snapshot;
ERROR: i
llegal txid_snapshot input format
ERROR: i
nvalid input for txid_snapshot: "12:16:14,14"
create table snapshot_test (
nr integer,
snap txid_snapshot
...
...
@@ -210,3 +210,12 @@ select txid_visible_in_snapshot('1000100010001015', '1000100010001000:1000100010
t
(1 row)
-- test 64bit overflow
SELECT txid_snapshot '1:9223372036854775807:3';
txid_snapshot
-------------------------
1:9223372036854775807:3
(1 row)
SELECT txid_snapshot '1:9223372036854775808:3';
ERROR: invalid input for txid_snapshot: "1:9223372036854775808:3"
contrib/txid/sql/txid.sql
View file @
b196b7fb
...
...
@@ -56,3 +56,6 @@ select txid_snapshot '1000100010001000:1000100010001100:1000100010001012,1000100
select
txid_visible_in_snapshot
(
'1000100010001012'
,
'1000100010001000:1000100010001100:1000100010001012,1000100010001013'
);
select
txid_visible_in_snapshot
(
'1000100010001015'
,
'1000100010001000:1000100010001100:1000100010001012,1000100010001013'
);
-- test 64bit overflow
SELECT
txid_snapshot
'1:9223372036854775807:3'
;
SELECT
txid_snapshot
'1:9223372036854775808:3'
;
contrib/txid/txid.c
View file @
b196b7fb
...
...
@@ -225,6 +225,39 @@ buf_finalize(StringInfo buf)
return
snap
;
}
/*
* simple number parser.
*
* We return 0 on error, which is invalid value for txid.
*/
static
txid
str2txid
(
const
char
*
s
,
const
char
**
endp
)
{
txid
val
=
0
;
for
(;
*
s
;
s
++
)
{
txid
last
=
val
;
if
(
*
s
<
'0'
||
*
s
>
'9'
)
break
;
val
=
val
*
10
+
(
*
s
-
'0'
);
/*
* check for overflow
*/
if
(
val
>
MAX_TXID
||
(
val
/
10
)
!=
last
)
{
val
=
0
;
break
;
}
}
if
(
endp
)
*
endp
=
s
;
return
val
;
}
/*
* parse snapshot from cstring
*/
...
...
@@ -234,21 +267,22 @@ parse_snapshot(const char *str)
txid
xmin
;
txid
xmax
;
txid
last_val
=
0
,
val
;
char
*
endp
;
const
char
*
str_start
=
str
;
const
char
*
endp
;
StringInfo
buf
;
xmin
=
(
txid
)
strtoull
(
str
,
&
endp
,
0
);
xmin
=
str2txid
(
str
,
&
endp
);
if
(
*
endp
!=
':'
)
goto
bad_format
;
str
=
endp
+
1
;
xmax
=
(
txid
)
strtoull
(
str
,
&
endp
,
0
);
xmax
=
str2txid
(
str
,
&
endp
);
if
(
*
endp
!=
':'
)
goto
bad_format
;
str
=
endp
+
1
;
/* it should look sane */
if
(
xmin
>
xmax
||
xmin
==
0
||
xmax
>
MAX_TXID
)
if
(
xmin
==
0
||
xmax
==
0
||
xmin
>
xmax
)
goto
bad_format
;
/* allocate buffer */
...
...
@@ -258,11 +292,11 @@ parse_snapshot(const char *str)
while
(
*
str
!=
'\0'
)
{
/* read next value */
val
=
(
txid
)
strtoull
(
str
,
&
endp
,
0
);
val
=
str2txid
(
str
,
&
endp
);
str
=
endp
;
/* require the input to be in order */
if
(
val
<
xmin
||
val
<=
last_val
||
val
>=
xmax
)
if
(
val
<
xmin
||
val
>=
xmax
||
val
<=
last_val
)
goto
bad_format
;
buf_add_txid
(
buf
,
val
);
...
...
@@ -277,7 +311,7 @@ parse_snapshot(const char *str)
return
buf_finalize
(
buf
);
bad_format:
elog
(
ERROR
,
"i
llegal txid_snapshot input format"
);
elog
(
ERROR
,
"i
nvalid input for txid_snapshot:
\"
%s
\"
"
,
str_start
);
return
NULL
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment