1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-05 07:21:24 +03:00

Fix bugs in plpgsql and ecpg caused by assuming that isspace() would only

return true for exactly the characters treated as whitespace by their flex
scanners.  Per report from Victor Snezhko and subsequent investigation.

Also fix a passel of unsafe usages of <ctype.h> functions, that is, ye olde
char-vs-unsigned-char issue.  I won't miss <ctype.h> when we are finally
able to stop using it.
This commit is contained in:
Tom Lane
2006-09-22 21:39:58 +00:00
parent 6d0efd3a09
commit beca984e5f
19 changed files with 112 additions and 61 deletions

View File

@ -12,7 +12,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/pgc.l,v 1.149 2006/08/18 15:59:35 meskes Exp $
* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/pgc.l,v 1.150 2006/09/22 21:39:58 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -47,6 +47,7 @@ static void addlit(char *ytext, int yleng);
static void addlitchar (unsigned char);
static void parse_include (void);
static void check_escape_warning(void);
static bool ecpg_isspace(char ch);
char *token_start;
int state_before;
@ -245,6 +246,9 @@ param \${integer}
* did not end with a newline.
*
* XXX perhaps \f (formfeed) should be treated as a newline as well?
*
* XXX if you change the set of whitespace characters, fix ecpg_isspace()
* to agree.
*/
ccomment "//".*\n
@ -872,7 +876,7 @@ cppline {space}*#(.*\\{space})*.*{newline}
* contains at least one non-space character plus the ";"
*/
for (i = strlen(yytext)-2;
i > 0 && isspace((unsigned char) yytext[i]);
i > 0 && ecpg_isspace(yytext[i]);
i-- )
;
yytext[i+1] = '\0';
@ -1060,7 +1064,7 @@ cppline {space}*#(.*\\{space})*.*{newline}
* contains at least one non-space character plus the ";"
*/
for (i = strlen(yytext)-2;
i > 0 && isspace((unsigned char) yytext[i]);
i > 0 && ecpg_isspace(yytext[i]);
i-- )
;
yytext[i+1] = '\0';
@ -1252,7 +1256,7 @@ parse_include(void)
* yytext contains at least one non-space character plus the ";"
*/
for (i = strlen(yytext)-2;
i > 0 && isspace((unsigned char) yytext[i]);
i > 0 && ecpg_isspace(yytext[i]);
i--)
;
@ -1328,3 +1332,18 @@ check_escape_warning(void)
mmerror (PARSE_ERROR, ET_WARNING, "nonstandard use of escape in a string literal");
warn_on_first_escape = false; /* warn only once per string */
}
/*
* ecpg_isspace() --- return TRUE if flex scanner considers char whitespace
*/
static bool
ecpg_isspace(char ch)
{
if (ch == ' ' ||
ch == '\t' ||
ch == '\n' ||
ch == '\r' ||
ch == '\f')
return true;
return false;
}

View File

@ -10,7 +10,7 @@
* exceed INITIAL_EXPBUFFER_SIZE (currently 256 bytes).
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-auth.c,v 1.119 2006/07/14 14:52:27 momjian Exp $
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-auth.c,v 1.120 2006/09/22 21:39:58 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -89,7 +89,7 @@ pg_an_to_ln(char *aname)
*p = '\0';
#ifdef WIN32
for (p = aname; *p; p++)
*p = pg_tolower(*p);
*p = pg_tolower((unsigned char) *p);
#endif
return aname;