Re: pgsql: Move strtoint() to common - Mailing list pgsql-committers
| From | Alvaro Herrera |
|---|---|
| Subject | Re: pgsql: Move strtoint() to common |
| Date | |
| Msg-id | 20180315191524.ga2fdjbnuz4y43fg@alvherre.pgsql Whole thread Raw |
| In response to | Re: pgsql: Move strtoint() to common (Tom Lane <tgl@sss.pgh.pa.us>) |
| Responses |
Re: pgsql: Move strtoint() to common
Re: pgsql: Move strtoint() to common |
| List | pgsql-committers |
Tom Lane wrote:
> Alvaro Herrera <alvherre@alvh.no-ip.org> writes:
> > Michael Paquier wrote:
> >> Attached is a patch which fixes the compilation failure on Windows for
> >> me. That should put the buildfarm back to green.
>
> > Pushed, thanks -- let's see how that goes.
>
> build now works, ecpg tests fail.
I stared at the code for a while, didn't notice anything amiss. I'm
mystified. Peter?
I think the guilty bit is the one below, but
1) I don't see how the new code fails to work exactly like the old code
2) I don't understand why it would only fail on Windows.
I thought it may be a port difference in strtol, but I don't see what
it'd be.
Also: it seems strtol per spec returns LONG_MAX/LONG_MIN on
overflow/underflow, and our strtoint doesn't do (an equivalent of) that.
But I don't see how that would affect the failing ecpg test.
diff --git a/src/interfaces/ecpg/preproc/pgc.l b/src/interfaces/ecpg/preproc/pgc.l
index ba1798c77e..405dee73b0 100644
*** a/src/interfaces/ecpg/preproc/pgc.l
--- b/src/interfaces/ecpg/preproc/pgc.l
***************
*** 723,744 **** cppline {space}*#([^i][A-Za-z]*|{if}|{ifdef}|{ifndef}|{import})((\/\*[^*/]*\*+
return Op;
}
<SQL>{param} {
base_yylval.ival = atol(yytext+1);
return PARAM;
}
<C,SQL>{integer} {
! long val;
char* endptr;
errno = 0;
! val = strtol((char *)yytext, &endptr,10);
! if (*endptr != '\0' || errno == ERANGE ||
! /* check for overflow of int */
! val != (int) val)
{
errno = 0;
base_yylval.str = mm_strdup(yytext);
return FCONST;
}
base_yylval.ival = val;
return ICONST;
--- 725,744 ----
return Op;
}
<SQL>{param} {
base_yylval.ival = atol(yytext+1);
return PARAM;
}
<C,SQL>{integer} {
! int val;
char* endptr;
errno = 0;
! val = strtoint(yytext, &endptr, 10);
! if (*endptr != '\0' || errno == ERANGE)
{
errno = 0;
base_yylval.str = mm_strdup(yytext);
return FCONST;
}
base_yylval.ival = val;
return ICONST;
--
Álvaro Herrera https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
pgsql-committers by date: