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? */

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