77 * Portions Copyright (c) 1996-2004, PostgreSQL Global Development Group
88 *
99 * IDENTIFICATION
10- * $PostgreSQL: pgsql/contrib/isn/isn.c,v 1.2 2006/09/10 20:45:17 tgl Exp $
10+ * $PostgreSQL: pgsql/contrib/isn/isn.c,v 1.3 2006/09/22 21:39:57 tgl Exp $
1111 *
1212 *-------------------------------------------------------------------------
1313 */
@@ -72,13 +72,16 @@ bool check_table(const char *(*TABLE)[2], const unsigned TABLE_index[10][2])
7272 aux2 = TABLE [i ][1 ];
7373
7474 /* must always start with a digit: */
75- if (!isdigit (* aux1 ) || !isdigit (* aux2 )) goto invalidtable ;
75+ if (!isdigit ((unsigned char ) * aux1 ) || !isdigit ((unsigned char ) * aux2 ))
76+ goto invalidtable ;
7677 a = * aux1 - '0' ;
7778 b = * aux2 - '0' ;
7879
7980 /* must always have the same format and length: */
8081 while (* aux1 && * aux2 ) {
81- if (!(isdigit (* aux1 ) && isdigit (* aux2 )) && (* aux1 != * aux2 || * aux1 != '-' ))
82+ if (!(isdigit ((unsigned char ) * aux1 ) &&
83+ isdigit ((unsigned char ) * aux2 )) &&
84+ (* aux1 != * aux2 || * aux1 != '-' ))
8285 goto invalidtable ;
8386 aux1 ++ ;
8487 aux2 ++ ;
@@ -124,7 +127,7 @@ unsigned dehyphenate(char *bufO, char *bufI)
124127{
125128 unsigned ret = 0 ;
126129 while (* bufI ) {
127- if (isdigit (* bufI )) {
130+ if (isdigit (( unsigned char ) * bufI )) {
128131 * bufO ++ = * bufI ;
129132 ret ++ ;
130133 }
@@ -183,7 +186,7 @@ unsigned hyphenate(char *bufO, char *bufI, const char *(*TABLE)[2], const unsign
183186
184187 firstdig ++ , ean_aux1 ++ , ean_aux2 ++ ;
185188 if (!(* ean_aux1 && * ean_aux2 && * firstdig )) break ;
186- if (!isdigit (* ean_aux1 )) ean_aux1 ++ , ean_aux2 ++ ;
189+ if (!isdigit (( unsigned char ) * ean_aux1 )) ean_aux1 ++ , ean_aux2 ++ ;
187190 } else {
188191 /* check in what direction we should go and move the pointer accordingly */
189192 if (* firstdig < * ean_aux1 && !ean_in1 ) upper = search ;
@@ -227,7 +230,7 @@ unsigned weight_checkdig(char *isn, unsigned size)
227230{
228231 unsigned weight = 0 ;
229232 while (* isn && size > 1 ) {
230- if (isdigit (* isn )) {
233+ if (isdigit (( unsigned char ) * isn )) {
231234 weight += size -- * (* isn - '0' );
232235 }
233236 isn ++ ;
@@ -254,7 +257,7 @@ unsigned checkdig(char *num, unsigned size)
254257 pos = 1 ;
255258 }
256259 while (* num && size > 1 ) {
257- if (isdigit (* num )) {
260+ if (isdigit (( unsigned char ) * num )) {
258261 if (pos ++ %2 ) check3 += * num - '0' ;
259262 else check += * num - '0' ;
260263 size -- ;
@@ -366,7 +369,7 @@ void ean2ISBN(char *isn)
366369 hyphenate (isn , isn + 4 , NULL , NULL );
367370 check = weight_checkdig (isn , 10 );
368371 aux = strchr (isn , '\0' );
369- while (!isdigit (* -- aux ));
372+ while (!isdigit (( unsigned char ) * -- aux ));
370373 if (check == 10 ) * aux = 'X' ;
371374 else * aux = check + '0' ;
372375}
@@ -411,7 +414,7 @@ ean13 str2ean(const char *num)
411414{
412415 ean13 ean = 0 ; /* current ean */
413416 while (* num ) {
414- if (isdigit (* num )) ean = 10 * ean + (* num - '0' );
417+ if (isdigit (( unsigned char ) * num )) ean = 10 * ean + (* num - '0' );
415418 num ++ ;
416419 }
417420 return (ean <<1 ); /* also give room to a flag */
@@ -570,7 +573,7 @@ bool string2ean(const char *str, bool errorOK, ean13 *result,
570573 /* recognize and validate the number: */
571574 while (* aux2 && length <= 13 ) {
572575 last = (* (aux2 + 1 ) == '!' || * (aux2 + 1 ) == '\0' ); /* is the last character */
573- digit = (isdigit (* aux2 )!= 0 ); /* is current character a digit? */
576+ digit = (isdigit (( unsigned char ) * aux2 )!= 0 ); /* is current character a digit? */
574577 if (* aux2 == '?' && last ) /* automagically calculate check digit if it's '?' */
575578 magic = digit = true;
576579 if (length == 0 && (* aux2 == 'M' || * aux2 == 'm' )) {
@@ -583,13 +586,13 @@ bool string2ean(const char *str, bool errorOK, ean13 *result,
583586 /* only ISSN can be here */
584587 if (type != INVALID ) goto eaninvalid ;
585588 type = ISSN ;
586- * aux1 ++ = toupper (* aux2 );
589+ * aux1 ++ = toupper (( unsigned char ) * aux2 );
587590 length ++ ;
588591 } else if (length == 9 && (digit || * aux2 == 'X' || * aux2 == 'x' ) && last ) {
589592 /* only ISBN and ISMN can be here */
590593 if (type != INVALID && type != ISMN ) goto eaninvalid ;
591594 if (type == INVALID ) type = ISBN ; /* ISMN must start with 'M' */
592- * aux1 ++ = toupper (* aux2 );
595+ * aux1 ++ = toupper (( unsigned char ) * aux2 );
593596 length ++ ;
594597 } else if (length == 11 && digit && last ) {
595598 /* only UPC can be here */
0 commit comments