]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Fix unportable usages of tolower(). On signed-char machines, it is necessary
authorTom Lane <tgl@sss.pgh.pa.us>
Sat, 1 Mar 2008 03:26:44 +0000 (03:26 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Sat, 1 Mar 2008 03:26:44 +0000 (03:26 +0000)
to explicitly cast the output back to char before comparing it to a char
value, else we get the wrong result for high-bit-set characters.  Found by
Rolf Jentsch.  Also, fix several places where <ctype.h> functions were being
called without casting the argument to unsigned char; this is likewise
unportable, but we keep making that mistake :-(.  These found by buildfarm
member salamander, which I will desperately miss if it ever goes belly-up.

src/backend/utils/adt/like_match.c
src/interfaces/ecpg/ecpglib/execute.c
src/interfaces/ecpg/preproc/preproc.y

index 915b9bd0d7ef4f7a1f5311bad10311808d4a4216..30d52d62c4258d17dbc864fcbcd1180fd2f8e9d6 100644 (file)
@@ -19,7 +19,7 @@
  * Copyright (c) 1996-2008, PostgreSQL Global Development Group
  *
  * IDENTIFICATION
- *     $PostgreSQL: pgsql/src/backend/utils/adt/like_match.c,v 1.20 2008/01/01 19:45:52 momjian Exp $
+ *     $PostgreSQL: pgsql/src/backend/utils/adt/like_match.c,v 1.20.2.1 2008/03/01 03:26:44 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -71,7 +71,7 @@
  */
 
 #ifdef MATCH_LOWER
-#define TCHAR(t) tolower((t))
+#define TCHAR(t) ((char) tolower((unsigned char) (t)))
 #else
 #define TCHAR(t) (t)
 #endif
index 20231c62a7df806108bcce8d98dd772ba96dab6f..d4e53b290e1a6b0339131efa0a99a371c2092ff8 100644 (file)
@@ -1,4 +1,4 @@
-/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/execute.c,v 1.76 2008/02/07 11:09:12 meskes Exp $ */
+/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/execute.c,v 1.76.2.1 2008/03/01 03:26:44 tgl Exp $ */
 
 /*
  * The aim is to get a simpler inteface to the database routines.
@@ -122,13 +122,15 @@ next_insert(char *text, int pos, bool questionmarks)
                        string = string ? false : true;
                else if (!string)
                {
-                       if (text[p] == '$' && isdigit(text[p + 1]))
+                       if (text[p] == '$' && isdigit((unsigned char) text[p + 1]))
                        {
                                /* this can be either a dollar quote or a variable */
                                int                     i;
 
-                               for (i = p + 1; isdigit(text[i]); i++);
-                               if (!isalpha(text[i]) && isascii(text[i]) && text[i] != '_')
+                               for (i = p + 1; isdigit((unsigned char) text[i]); i++)
+                                       /* empty loop body */ ;
+                               if (!isalpha((unsigned char) text[i]) &&
+                                       isascii((unsigned char) text[i]) && text[i] != '_')
                                        /* not dollar delimited quote */
                                        return p;
                        }
index 5b7cef224c41a7c1c22f3eb8fc57c3f882edb5d6..8f660694a183a8cec5defae68ab11596414debe3 100644 (file)
@@ -1,4 +1,4 @@
-/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/preproc.y,v 1.359.2.1 2008/02/15 12:11:02 meskes Exp $ */
+/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/preproc.y,v 1.359.2.2 2008/03/01 03:26:44 tgl Exp $ */
 
 /* Copyright comment */
 %{
@@ -5845,7 +5845,7 @@ prepared_name: name               {
                                                int i;
 
                                                for (i = 0; i< strlen($1); i++)
-                                                       $1[i] = tolower($1[i]);
+                                                       $1[i] = tolower((unsigned char) $1[i]);
 
                                                $$ = make3_str(make_str("\""), $1, make_str("\""));
                                        }