From 3df9100cd960c682ab78c015a344925fab52b988 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Sat, 1 Mar 2008 03:26:44 +0000 Subject: [PATCH] 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 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 | 2 +- src/interfaces/ecpg/ecpglib/execute.c | 8 +++++--- src/interfaces/ecpg/preproc/preproc.y | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/backend/utils/adt/like_match.c b/src/backend/utils/adt/like_match.c index 7d32426cb4..91e5778b38 100644 --- a/src/backend/utils/adt/like_match.c +++ b/src/backend/utils/adt/like_match.c @@ -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 diff --git a/src/interfaces/ecpg/ecpglib/execute.c b/src/interfaces/ecpg/ecpglib/execute.c index 7649235f31..f496c705ba 100644 --- a/src/interfaces/ecpg/ecpglib/execute.c +++ b/src/interfaces/ecpg/ecpglib/execute.c @@ -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; } diff --git a/src/interfaces/ecpg/preproc/preproc.y b/src/interfaces/ecpg/preproc/preproc.y index d9f5999c99..1b6763b23f 100644 --- a/src/interfaces/ecpg/preproc/preproc.y +++ b/src/interfaces/ecpg/preproc/preproc.y @@ -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("\"")); } -- 2.39.5