Skip to content

Commit e04fa58

Browse files
committed
Fix unportable usages of tolower(). On signed-char machines, it is necessary
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.
1 parent 3bf822c commit e04fa58

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

src/backend/utils/adt/like_match.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
* Copyright (c) 1996-2008, PostgreSQL Global Development Group
2020
*
2121
* IDENTIFICATION
22-
* $PostgreSQL: pgsql/src/backend/utils/adt/like_match.c,v 1.20 2008/01/01 19:45:52 momjian Exp $
22+
* $PostgreSQL: pgsql/src/backend/utils/adt/like_match.c,v 1.21 2008/03/01 03:26:34 tgl Exp $
2323
*
2424
*-------------------------------------------------------------------------
2525
*/
@@ -71,7 +71,7 @@
7171
*/
7272

7373
#ifdef MATCH_LOWER
74-
#define TCHAR(t) tolower((t))
74+
#define TCHAR(t) ((char) tolower((unsigned char) (t)))
7575
#else
7676
#define TCHAR(t) (t)
7777
#endif

src/interfaces/ecpg/ecpglib/execute.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/execute.c,v 1.76 2008/02/07 11:09:12 meskes Exp $ */
1+
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/execute.c,v 1.77 2008/03/01 03:26:34 tgl Exp $ */
22

33
/*
44
* The aim is to get a simpler inteface to the database routines.
@@ -122,13 +122,15 @@ next_insert(char *text, int pos, bool questionmarks)
122122
string = string ? false : true;
123123
else if (!string)
124124
{
125-
if (text[p] == '$' && isdigit(text[p + 1]))
125+
if (text[p] == '$' && isdigit((unsigned char) text[p + 1]))
126126
{
127127
/* this can be either a dollar quote or a variable */
128128
int i;
129129

130-
for (i = p + 1; isdigit(text[i]); i++);
131-
if (!isalpha(text[i]) && isascii(text[i]) && text[i] != '_')
130+
for (i = p + 1; isdigit((unsigned char) text[i]); i++)
131+
/* empty loop body */ ;
132+
if (!isalpha((unsigned char) text[i]) &&
133+
isascii((unsigned char) text[i]) && text[i] != '_')
132134
/* not dollar delimited quote */
133135
return p;
134136
}

src/interfaces/ecpg/preproc/preproc.y

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/preproc.y,v 1.361 2008/02/15 22:17:06 tgl Exp $ */
1+
/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/preproc.y,v 1.362 2008/03/01 03:26:35 tgl Exp $ */
22

33
/* Copyright comment */
44
%{
@@ -5847,7 +5847,7 @@ prepared_name: name {
58475847
int i;
58485848

58495849
for (i = 0; i< strlen($1); i++)
5850-
$1[i] = tolower($1[i]);
5850+
$1[i] = tolower((unsigned char) $1[i]);
58515851

58525852
$$ = make3_str(make_str("\""), $1, make_str("\""));
58535853
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy