Skip to content

Commit ee051ba

Browse files
committed
Make sure that all <ctype.h> routines are called with unsigned char
values; it's not portable to call them with signed chars. I recall doing this for the last release, but a few more uncasted calls have snuck in.
1 parent e7d9a6b commit ee051ba

File tree

7 files changed

+23
-22
lines changed

7 files changed

+23
-22
lines changed

contrib/dbase/dbf2pg.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ isinteger(char *buff)
7878
i++;
7979
continue;
8080
}
81-
if (!isdigit((int) *i))
81+
if (!isdigit((unsigned char) *i))
8282
return 0;
8383
i++;
8484
}
@@ -90,7 +90,7 @@ strtoupper(char *string)
9090
{
9191
while (*string != '\0')
9292
{
93-
*string = toupper(*string);
93+
*string = toupper((unsigned char) *string);
9494
string++;
9595
}
9696
}
@@ -100,7 +100,7 @@ strtolower(char *string)
100100
{
101101
while (*string != '\0')
102102
{
103-
*string = tolower(*string);
103+
*string = tolower((unsigned char) *string);
104104
string++;
105105
}
106106
}

contrib/fuzzystrmatch/fuzzystrmatch.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -253,17 +253,18 @@ metaphone(PG_FUNCTION_ARGS)
253253
* accesssing the array directly... */
254254

255255
/* Look at the next letter in the word */
256-
#define Next_Letter (toupper(word[w_idx+1]))
256+
#define Next_Letter (toupper((unsigned char) word[w_idx+1]))
257257
/* Look at the current letter in the word */
258-
#define Curr_Letter (toupper(word[w_idx]))
258+
#define Curr_Letter (toupper((unsigned char) word[w_idx]))
259259
/* Go N letters back. */
260-
#define Look_Back_Letter(n) (w_idx >= n ? toupper(word[w_idx-n]) : '\0')
260+
#define Look_Back_Letter(n) \
261+
(w_idx >= (n) ? toupper((unsigned char) word[w_idx-(n)]) : '\0')
261262
/* Previous letter. I dunno, should this return null on failure? */
262263
#define Prev_Letter (Look_Back_Letter(1))
263264
/* Look two letters down. It makes sure you don't walk off the string. */
264-
#define After_Next_Letter (Next_Letter != '\0' ? toupper(word[w_idx+2]) \
265-
: '\0')
266-
#define Look_Ahead_Letter(n) (toupper(Lookahead(word+w_idx, n)))
265+
#define After_Next_Letter \
266+
(Next_Letter != '\0' ? toupper((unsigned char) word[w_idx+2]) : '\0')
267+
#define Look_Ahead_Letter(n) toupper((unsigned char) Lookahead(word+w_idx, n))
267268

268269

269270
/* Allows us to safely look ahead an arbitrary # of letters */
@@ -291,7 +292,7 @@ Lookahead(char *word, int how_far)
291292
#define Phone_Len (p_idx)
292293

293294
/* Note is a letter is a 'break' in the word */
294-
#define Isbreak(c) (!isalpha(c))
295+
#define Isbreak(c) (!isalpha((unsigned char) (c)))
295296

296297

297298
int
@@ -336,7 +337,7 @@ _metaphone(
336337

337338
/*-- The first phoneme has to be processed specially. --*/
338339
/* Find our first letter */
339-
for (; !isalpha(Curr_Letter); w_idx++)
340+
for (; !isalpha((unsigned char) (Curr_Letter)); w_idx++)
340341
{
341342
/* On the off chance we were given nothing but crap... */
342343
if (Curr_Letter == '\0')
@@ -435,7 +436,7 @@ _metaphone(
435436
*/
436437

437438
/* Ignore non-alphas */
438-
if (!isalpha(Curr_Letter))
439+
if (!isalpha((unsigned char) (Curr_Letter)))
439440
continue;
440441

441442
/* Drop duplicates, except CC */

contrib/fuzzystrmatch/fuzzystrmatch.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ char _codes[26] = {
153153
};
154154

155155

156-
#define ENCODE(c) (isalpha(c) ? _codes[((toupper(c)) - 'A')] : 0)
156+
#define ENCODE(c) (isalpha((unsigned char) (c)) ? _codes[((toupper((unsigned char) (c))) - 'A')] : 0)
157157

158158
#define isvowel(c) (ENCODE(c) & 1) /* AEIOU */
159159

contrib/pgcrypto/pgcrypto.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2727
* SUCH DAMAGE.
2828
*
29-
* $Id: pgcrypto.c,v 1.11 2001/11/20 15:50:53 momjian Exp $
29+
* $Id: pgcrypto.c,v 1.12 2001/12/30 23:09:41 tgl Exp $
3030
*/
3131

3232
#include <postgres.h>
@@ -556,7 +556,7 @@ find_provider(text *name,
556556

557557
p = VARDATA(name);
558558
for (i = 0; i < len; i++)
559-
buf[i] = tolower(p[i]);
559+
buf[i] = tolower((unsigned char) p[i]);
560560
buf[len] = 0;
561561

562562
err = provider_lookup(buf, &res);

src/backend/utils/adt/datetime.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/datetime.c,v 1.85 2001/12/29 21:28:18 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/datetime.c,v 1.86 2001/12/30 23:09:41 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -959,7 +959,7 @@ DecodeDateTime(char **field, int *ftype, int nf,
959959
if (tzp == NULL)
960960
return -1;
961961

962-
if (isdigit(*field[i]) || ptype != 0)
962+
if (isdigit((unsigned char) *field[i]) || ptype != 0)
963963
{
964964
char *cp;
965965

@@ -1573,7 +1573,7 @@ DecodeTimeOnly(char **field, int *ftype, int nf,
15731573
/* otherwise, this is a time and/or time zone */
15741574
else
15751575
{
1576-
if (isdigit(*field[i]))
1576+
if (isdigit((unsigned char) *field[i]))
15771577
{
15781578
char *cp;
15791579

src/interfaces/odbc/connection.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1092,7 +1092,7 @@ CC_send_query(ConnectionClass *self, char *query, QueryInfo *qi)
10921092

10931093
ReadyToReturn = FALSE;
10941094
empty_reqs = 0;
1095-
for (wq = query; isspace(*wq); wq++)
1095+
for (wq = query; isspace((unsigned char) *wq); wq++)
10961096
;
10971097
if (*wq == '\0')
10981098
empty_reqs = 1;

src/interfaces/odbc/convert.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ timestamp2stime(const char *str, SIMPLE_TIME *st, BOOL *bZone, int *zone)
193193
}
194194
for (i = 1; i < 10; i++)
195195
{
196-
if (!isdigit(rest[i]))
196+
if (!isdigit((unsigned char) rest[i]))
197197
break;
198198
}
199199
for (; i < 10; i++)
@@ -1351,7 +1351,7 @@ copy_statement_with_parameters(StatementClass *stmt)
13511351
while (isspace((unsigned char) old_statement[++opos]));
13521352
}
13531353
if (strnicmp(&old_statement[opos], "call", lit_call_len) ||
1354-
!isspace(old_statement[opos + lit_call_len]))
1354+
!isspace((unsigned char) old_statement[opos + lit_call_len]))
13551355
{
13561356
opos--;
13571357
continue;
@@ -1407,7 +1407,7 @@ copy_statement_with_parameters(StatementClass *stmt)
14071407
in_dquote = TRUE;
14081408
else
14091409
{
1410-
if (isspace(oldchar))
1410+
if (isspace((unsigned char) oldchar))
14111411
{
14121412
if (!prev_token_end)
14131413
{

0 commit comments

Comments
 (0)