@@ -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
297298int
@@ -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... */
342343if (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 ) ))
439440continue ;
440441
441442/* Drop duplicates, except CC */