timeline signedness

Поиск
Список
Период
Сортировка
Искать

timeline signedness

От:
Peter Eisentraut <peter_e@gmx.net>
Дата:
WAL timelines are unsigned 32-bit integers everywhere, except the
replication parser (replication/repl_gram.y and
replication/repl_scanner.l) treats them as signed 32-bit integers.  It's
obviously a corner case, but it would be prudent to be correct about
this.  It should be easy to fix in those grammar files.




Re: timeline signedness

От:
Peter Eisentraut <peter_e@gmx.net>
Дата:
On Wed, 2013-08-07 at 21:55 -0400, Peter Eisentraut wrote:
> WAL timelines are unsigned 32-bit integers everywhere, except the
> replication parser (replication/repl_gram.y and
> replication/repl_scanner.l) treats them as signed 32-bit integers.  It's
> obviously a corner case, but it would be prudent to be correct about
> this.  It should be easy to fix in those grammar files.

Here is a patch to fix this.
diff --git a/src/backend/replication/repl_gram.y b/src/backend/replication/repl_gram.y
index bce18b8..f465530 100644
--- a/src/backend/replication/repl_gram.y
+++ b/src/backend/replication/repl_gram.y
@@ -56,7 +56,7 @@ Node *replication_parse_result;
 %union {
 		char					*str;
 		bool					boolval;
-		int32					intval;
+		uint32					uintval;
 
 		XLogRecPtr				recptr;
 		Node					*node;
@@ -66,7 +66,7 @@ Node *replication_parse_result;
 
 /* Non-keyword tokens */
 %token  SCONST
-%token  ICONST
+%token  UCONST
 %token  RECPTR
 
 /* Keyword tokens. */
@@ -85,7 +85,7 @@ Node *replication_parse_result;
 %type 	base_backup start_replication identify_system timeline_history
 %type 	base_backup_opt_list
 %type 	base_backup_opt
-%type 	opt_timeline
+%type 	opt_timeline
 %%
 
 firstcmd: command opt_semicolon
@@ -175,14 +175,7 @@ start_replication:
 			;
 
 opt_timeline:
-			K_TIMELINE ICONST
-				{
-					if ($2 <= 0)
-						ereport(ERROR,
-								(errcode(ERRCODE_SYNTAX_ERROR),
-								 (errmsg("invalid timeline %d", $2))));
-					$$ = $2;
-				}
+			K_TIMELINE UCONST			{ $$ = $2; }
 				| /* nothing */			{ $$ = 0; }
 			;
 
@@ -190,15 +183,10 @@ opt_timeline:
  * TIMELINE_HISTORY %d
  */
 timeline_history:
-			K_TIMELINE_HISTORY ICONST
+			K_TIMELINE_HISTORY UCONST
 				{
 					TimeLineHistoryCmd *cmd;
 
-					if ($2 <= 0)
-						ereport(ERROR,
-								(errcode(ERRCODE_SYNTAX_ERROR),
-								 (errmsg("invalid timeline %d", $2))));
-
 					cmd = makeNode(TimeLineHistoryCmd);
 					cmd->timeline = $2;
 
diff --git a/src/backend/replication/repl_scanner.l b/src/backend/replication/repl_scanner.l
index b4743e6..3d930f1 100644
--- a/src/backend/replication/repl_scanner.l
+++ b/src/backend/replication/repl_scanner.l
@@ -83,8 +83,8 @@ TIMELINE_HISTORY	{ return K_TIMELINE_HISTORY; }
 " "				;
 
 {digit}+		{
-					yylval.intval = pg_atoi(yytext, sizeof(int32), 0);
-					return ICONST;
+					yylval.uintval = strtoul(yytext, NULL, 10);
+					return UCONST;
 				}
 
 {hexdigit}+\/{hexdigit}+		{

Re: timeline signedness

От:
Magnus Hagander <magnus@hagander.net>
Дата:
On Tue, Aug 13, 2013 at 1:31 PM, Peter Eisentraut  wrote:
> On Wed, 2013-08-07 at 21:55 -0400, Peter Eisentraut wrote:
>> WAL timelines are unsigned 32-bit integers everywhere, except the
>> replication parser (replication/repl_gram.y and
>> replication/repl_scanner.l) treats them as signed 32-bit integers.  It's
>> obviously a corner case, but it would be prudent to be correct about
>> this.  It should be easy to fix in those grammar files.
>
> Here is a patch to fix this.

Looks fine to me, and looks like the correct thing to do.

-- Magnus HaganderMe: http://www.hagander.net/Work: http://www.redpill-linpro.com/


Re: timeline signedness

От:
Heikki Linnakangas <hlinnakangas@vmware.com>
Дата:
On 13.08.2013 14:31, Peter Eisentraut wrote:
> On Wed, 2013-08-07 at 21:55 -0400, Peter Eisentraut wrote:
>> WAL timelines are unsigned 32-bit integers everywhere, except the
>> replication parser (replication/repl_gram.y and
>> replication/repl_scanner.l) treats them as signed 32-bit integers.  It's
>> obviously a corner case, but it would be prudent to be correct about
>> this.  It should be easy to fix in those grammar files.

+1

> Here is a patch to fix this.

If I'm reading this correctly, timeline 0 no longer throws an error with 
this patch.

- Heikki


Re: timeline signedness

От:
Peter Eisentraut <peter_e@gmx.net>
Дата:
On Wed, 2013-08-14 at 16:20 +0300, Heikki Linnakangas wrote:
> On 13.08.2013 14:31, Peter Eisentraut wrote:
> > On Wed, 2013-08-07 at 21:55 -0400, Peter Eisentraut wrote:
> >> WAL timelines are unsigned 32-bit integers everywhere, except the
> >> replication parser (replication/repl_gram.y and
> >> replication/repl_scanner.l) treats them as signed 32-bit integers.  It's
> >> obviously a corner case, but it would be prudent to be correct about
> >> this.  It should be easy to fix in those grammar files.
> 
> +1
> 
> > Here is a patch to fix this.
> 
> If I'm reading this correctly, timeline 0 no longer throws an error with 
> this patch.

Fixed that.



FAQ