Skip to content

Commit a27b691

Browse files
committed
Ensure that all uses of <ctype.h> functions are applied to unsigned-char
values, whether the local char type is signed or not. This is necessary for portability. Per discussion on pghackers around 9/16/00.
1 parent 4d2a506 commit a27b691

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+318
-303
lines changed

contrib/fulltextindex/fti.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include "postgres.h"
22
#include "executor/spi.h"
33
#include "commands/trigger.h"
4-
#include <ctype.h> /* tolower */
4+
#include <ctype.h>
55
#include <stdio.h> /* debugging */
66

77
/*
@@ -256,10 +256,9 @@ fti(PG_FUNCTION_ARGS)
256256
char *string = column;
257257

258258
while (*string != '\0')
259-
{ /* placed 'really' inline. */
260-
*string = tolower(*string); /* some compilers will
261-
* choke */
262-
string++; /* on 'inline' keyword */
259+
{
260+
*string = tolower((unsigned char) *string);
261+
string++;
263262
}
264263

265264
data = (struct varlena *) palloc(sizeof(int32) + strlen(column) +1);
@@ -312,9 +311,9 @@ breakup(char *string, char *substring)
312311
* (ie. 'string$%^&', last_start first points to '&', and after
313312
* this to 'g'
314313
*/
315-
if (!isalnum((int) *last_start))
314+
if (!isalnum((unsigned char) *last_start))
316315
{
317-
while (!isalnum((int) *last_start) &&
316+
while (!isalnum((unsigned char) *last_start) &&
318317
last_start > string)
319318
last_start--;
320319
cur_pos = last_start;
@@ -323,7 +322,7 @@ breakup(char *string, char *substring)
323322
cur_pos--; /* substrings are at minimum 2 characters
324323
* long */
325324

326-
if (isalnum((int) *cur_pos))
325+
if (isalnum((unsigned char) *cur_pos))
327326
{
328327
/* Houston, we have a substring! :) */
329328
memcpy(substring, cur_pos, last_start - cur_pos + 1);

contrib/soundex/soundex.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $Header: /cvsroot/pgsql/contrib/soundex/Attic/soundex.c,v 1.8 2000/11/20 20:36:57 tgl Exp $ */
1+
/* $Header: /cvsroot/pgsql/contrib/soundex/Attic/soundex.c,v 1.9 2000/12/03 20:45:31 tgl Exp $ */
22
#include "postgres.h"
33
#include "fmgr.h"
44
#include "utils/builtins.h"
@@ -42,7 +42,7 @@ text_soundex(PG_FUNCTION_ARGS)
4242

4343
/* ABCDEFGHIJKLMNOPQRSTUVWXYZ */
4444
static const char *soundex_table = "01230120022455012623010202";
45-
#define soundex_code(letter) soundex_table[toupper(letter) - 'A']
45+
#define soundex_code(letter) soundex_table[toupper((unsigned char) (letter)) - 'A']
4646

4747

4848
static void
@@ -56,7 +56,7 @@ soundex(const char *instr, char *outstr)
5656
outstr[SOUNDEX_LEN] = '\0';
5757

5858
/* Skip leading non-alphabetic characters */
59-
while (!isalpha(instr[0]) && instr[0])
59+
while (!isalpha((unsigned char) instr[0]) && instr[0])
6060
++instr;
6161

6262
/* No string left */
@@ -67,12 +67,13 @@ soundex(const char *instr, char *outstr)
6767
}
6868

6969
/* Take the first letter as is */
70-
*outstr++ = (char) toupper(*instr++);
70+
*outstr++ = (char) toupper((unsigned char) *instr++);
7171

7272
count = 1;
7373
while (*instr && count < SOUNDEX_LEN)
7474
{
75-
if (isalpha(*instr) && soundex_code(*instr) != soundex_code(*(instr - 1)))
75+
if (isalpha((unsigned char) *instr) &&
76+
soundex_code(*instr) != soundex_code(*(instr - 1)))
7677
{
7778
*outstr = soundex_code(instr[0]);
7879
if (*outstr != '0')

contrib/spi/preprocessor/step1.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ strtoupper(char *string)
66
int i;
77

88
for (i = 0; i < strlen(string); i++)
9-
string[i] = toupper(string[i]);
9+
string[i] = toupper((unsigned char) string[i]);
1010
return string;
1111
}
1212

contrib/spi/refint.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
#include "executor/spi.h" /* this is what you need to work with SPI */
77
#include "commands/trigger.h" /* -"- and triggers */
8-
#include <ctype.h> /* tolower () */
8+
#include <ctype.h>
99

1010

1111
extern Datum check_primary_key(PG_FUNCTION_ARGS);
@@ -293,7 +293,7 @@ check_foreign_key(PG_FUNCTION_ARGS)
293293
nrefs = pg_atoi(args[0], sizeof(int), 0);
294294
if (nrefs < 1)
295295
elog(ERROR, "check_foreign_key: %d (< 1) number of references specified", nrefs);
296-
action = tolower(*(args[1]));
296+
action = tolower((unsigned char) *(args[1]));
297297
if (action != 'r' && action != 'c' && action != 's')
298298
elog(ERROR, "check_foreign_key: invalid action %s", args[1]);
299299
nargs -= 2;

contrib/spi/timetravel.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
#include "executor/spi.h" /* this is what you need to work with SPI */
77
#include "commands/trigger.h" /* -"- and triggers */
8-
#include <ctype.h> /* tolower () */
8+
#include <ctype.h>
99

1010
#define ABSTIMEOID 702 /* it should be in pg_type.h */
1111

@@ -376,7 +376,7 @@ set_timetravel(PG_FUNCTION_ARGS)
376376
NameGetDatum(relname)));
377377
d = TTOff[nTTOff] = malloc(strlen(rname) + 1);
378378
while (*s)
379-
*d++ = tolower(*s++);
379+
*d++ = tolower((unsigned char) *s++);
380380
*d = 0;
381381
pfree(rname);
382382
nTTOff++;

contrib/string/string_io.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,10 @@
2828
#define DIGIT(val) ((val) + '0')
2929
#define ISOCTAL(c) (((c) >= '0') && ((c) <= '7'))
3030
#ifndef ISO8859
31-
#define NOTPRINTABLE(c) (!isprint(c))
31+
#define NOTPRINTABLE(c) (!isprint((unsigned char) (c)))
3232
#else
33-
#define NOTPRINTABLE(c) (!isprint(c) && ((c) < 0xa0))
33+
#define NOTPRINTABLE(c) (!isprint((unsigned char) (c)) && \
34+
((unsigned char) (c) < (unsigned char) 0xa0))
3435
#endif
3536

3637
/*

src/backend/commands/define.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
*
1212
* IDENTIFICATION
13-
* $Header: /cvsroot/pgsql/src/backend/commands/define.c,v 1.49 2000/11/20 20:36:47 tgl Exp $
13+
* $Header: /cvsroot/pgsql/src/backend/commands/define.c,v 1.50 2000/12/03 20:45:33 tgl Exp $
1414
*
1515
* DESCRIPTION
1616
* The "DefineFoo" routines take the parse tree and pick out the
@@ -71,7 +71,7 @@ case_translate_language_name(const char *input, char *output)
7171
int i;
7272

7373
for (i = 0; i < NAMEDATALEN-1 && input[i]; ++i)
74-
output[i] = tolower(input[i]);
74+
output[i] = tolower((unsigned char) input[i]);
7575

7676
output[i] = '\0';
7777

src/backend/commands/proclang.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ case_translate_language_name(const char *input, char *output)
3131
int i;
3232

3333
for (i = 0; i < NAMEDATALEN && input[i]; ++i)
34-
output[i] = tolower(input[i]);
34+
output[i] = tolower((unsigned char) input[i]);
3535

3636
output[i] = '\0';
3737

src/backend/commands/sequence.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -473,9 +473,8 @@ get_seq_name(text *seqin)
473473
*/
474474
for (; *rawname; rawname++)
475475
{
476-
if (isascii((int) *rawname) &&
477-
isupper((int) *rawname))
478-
*rawname = tolower(*rawname);
476+
if (isupper((unsigned char) *rawname))
477+
*rawname = tolower((unsigned char) *rawname);
479478
}
480479
}
481480
return seqname;

src/backend/commands/variable.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $Header: /cvsroot/pgsql/src/backend/commands/variable.c,v 1.43 2000/10/26 17:31:34 tgl Exp $
12+
* $Header: /cvsroot/pgsql/src/backend/commands/variable.c,v 1.44 2000/12/03 20:45:33 tgl Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -104,7 +104,7 @@ get_token(char **tok, char **val, char *str)
104104
return NULL;
105105

106106
/* skip leading white space */
107-
while (isspace((int) *str))
107+
while (isspace((unsigned char) *str))
108108
str++;
109109

110110
/* end of string? then return NULL */
@@ -118,15 +118,16 @@ get_token(char **tok, char **val, char *str)
118118
*tok = str;
119119

120120
/* Advance to end of word */
121-
while (*str && !isspace((int) *str) && *str != ',' && *str != '=')
121+
while (*str && !isspace((unsigned char) *str) &&
122+
*str != ',' && *str != '=')
122123
str++;
123124

124125
/* Terminate word string for caller */
125126
ch = *str;
126127
*str = '\0';
127128

128129
/* Skip any whitespace */
129-
while (isspace((int) ch))
130+
while (isspace((unsigned char) ch))
130131
ch = *(++str);
131132

132133
/* end of string? */
@@ -144,7 +145,7 @@ get_token(char **tok, char **val, char *str)
144145
str++;
145146

146147
/* skip whitespace after '=' */
147-
while (isspace((int) *str))
148+
while (isspace((unsigned char) *str))
148149
str++;
149150

150151
if (*str == ',' || *str == '\0')
@@ -154,15 +155,15 @@ get_token(char **tok, char **val, char *str)
154155
*val = str;
155156

156157
/* Advance to end of word */
157-
while (*str && !isspace((int) *str) && *str != ',')
158+
while (*str && !isspace((unsigned char) *str) && *str != ',')
158159
str++;
159160

160161
/* Terminate word string for caller */
161162
ch = *str;
162163
*str = '\0';
163164

164165
/* Skip any whitespace */
165-
while (isspace((int) ch))
166+
while (isspace((unsigned char) ch))
166167
ch = *(++str);
167168

168169
/* end of string? */

src/backend/libpq/auth.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/libpq/auth.c,v 1.49 2000/08/25 10:00:30 petere Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/libpq/auth.c,v 1.50 2000/12/03 20:45:33 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -23,7 +23,7 @@
2323
#include <netdb.h> /* for MAXHOSTNAMELEN on some */
2424
#endif
2525
#include <pwd.h>
26-
#include <ctype.h> /* isspace() declaration */
26+
#include <ctype.h>
2727

2828
#include <sys/types.h> /* needed by in.h on Ultrix */
2929
#include <netinet/in.h>

src/backend/nodes/outfuncs.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
9-
* $Header: /cvsroot/pgsql/src/backend/nodes/outfuncs.c,v 1.134 2000/11/16 22:30:23 tgl Exp $
9+
* $Header: /cvsroot/pgsql/src/backend/nodes/outfuncs.c,v 1.135 2000/12/03 20:45:33 tgl Exp $
1010
*
1111
* NOTES
1212
* Every (plan) node in POSTGRES has an associated "out" routine which
@@ -70,8 +70,8 @@ _outToken(StringInfo str, char *s)
7070
if (*s == '<' ||
7171
*s == '\"' ||
7272
*s == '@' ||
73-
isdigit((int) *s) ||
74-
(*s == '-' && isdigit((int) s[1])))
73+
isdigit((unsigned char) *s) ||
74+
(*s == '-' && isdigit((unsigned char) s[1])))
7575
appendStringInfoChar(str, '\\');
7676
while (*s)
7777
{

src/backend/nodes/read.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $Header: /cvsroot/pgsql/src/backend/nodes/read.c,v 1.25 2000/10/31 13:59:52 petere Exp $
12+
* $Header: /cvsroot/pgsql/src/backend/nodes/read.c,v 1.26 2000/12/03 20:45:33 tgl Exp $
1313
*
1414
* HISTORY
1515
* AUTHOR DATE MAJOR EVENT
@@ -205,8 +205,8 @@ nodeTokenType(char *token, int length)
205205
numlen = length;
206206
if (*numptr == '+' || *numptr == '-')
207207
numptr++, numlen--;
208-
if ((numlen > 0 && isdigit((int) *numptr)) ||
209-
(numlen > 1 && *numptr == '.' && isdigit((int) numptr[1])))
208+
if ((numlen > 0 && isdigit((unsigned char) *numptr)) ||
209+
(numlen > 1 && *numptr == '.' && isdigit((unsigned char) numptr[1])))
210210
{
211211

212212
/*

src/backend/parser/parse_node.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/parser/parse_node.c,v 1.49 2000/11/16 22:30:28 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/parser/parse_node.c,v 1.50 2000/12/03 20:45:34 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -533,7 +533,7 @@ fitsInFloat(Value *value)
533533
ndigits = 0;
534534
for (; *ptr; ptr++)
535535
{
536-
if (isdigit((int) *ptr))
536+
if (isdigit((unsigned char) *ptr))
537537
ndigits++;
538538
else if (*ptr == 'e' || *ptr == 'E')
539539
break; /* don't count digits in exponent */

src/backend/parser/scan.l

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $Header: /cvsroot/pgsql/src/backend/parser/scan.l,v 1.83 2000/11/16 22:47:44 petere Exp $
12+
* $Header: /cvsroot/pgsql/src/backend/parser/scan.l,v 1.84 2000/12/03 20:45:34 tgl Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -478,9 +478,8 @@ other .
478478
ScanKeyword *keyword;
479479

480480
for(i = 0; yytext[i]; i++)
481-
if (isascii((int) yytext[i]) &&
482-
isupper((int) yytext[i]))
483-
yytext[i] = tolower(yytext[i]);
481+
if (isupper((unsigned char) yytext[i]))
482+
yytext[i] = tolower((unsigned char) yytext[i]);
484483
if (i >= NAMEDATALEN)
485484
{
486485
#ifdef MULTIBYTE

src/backend/port/inet_aton.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $Id: inet_aton.c,v 1.17 1999/07/17 04:12:09 momjian Exp $
1+
/* $Id: inet_aton.c,v 1.18 2000/12/03 20:45:34 tgl Exp $
22
*
33
* This inet_aton() function was taken from the GNU C library and
44
* incorporated into Postgres for those systems which do not have this
@@ -83,16 +83,16 @@ inet_aton(const char *cp, struct in_addr * addr)
8383
}
8484
while ((c = *cp) != '\0')
8585
{
86-
if (isascii(c) && isdigit(c))
86+
if (isdigit((unsigned char) c))
8787
{
8888
val = (val * base) + (c - '0');
8989
cp++;
9090
continue;
9191
}
92-
if (base == 16 && isascii(c) && isxdigit(c))
92+
if (base == 16 && isxdigit((unsigned char) c))
9393
{
9494
val = (val << 4) +
95-
(c + 10 - (islower(c) ? 'a' : 'A'));
95+
(c + 10 - (islower((unsigned char) c) ? 'a' : 'A'));
9696
cp++;
9797
continue;
9898
}
@@ -114,10 +114,11 @@ inet_aton(const char *cp, struct in_addr * addr)
114114
}
115115

116116
/*
117-
* Check for trailing characters.
117+
* Check for trailing junk.
118118
*/
119-
if (*cp && (!isascii(*cp) || !isspace(*cp)))
120-
return 0;
119+
while (*cp)
120+
if (!isspace((unsigned char) *cp++))
121+
return 0;
121122

122123
/*
123124
* Concoct the address according to the number of parts specified.

0 commit comments

Comments
 (0)