Skip to content

Commit 4351f88

Browse files
committed
Fix portability bugs: char values passed to <ctype.h> functions must
be cast to unsigned char. We have learned this the hard way before.
1 parent 558ed5a commit 4351f88

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

src/interfaces/ecpg/compatlib/informix.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ rstrdate(char *str, date * d)
464464
for (i=0,j=0; i < 10; i++ )
465465
{
466466
/* ignore non-digits */
467-
if ( isdigit(str[i]) )
467+
if ( isdigit((unsigned char) str[i]) )
468468
{
469469

470470
/* j only increments if it is a digit */
@@ -910,8 +910,8 @@ void
910910
rupshift(char *str)
911911
{
912912
for (; *str != '\0'; str++)
913-
if (islower(*str))
914-
*str = toupper(*str);
913+
if (islower((unsigned char) *str))
914+
*str = toupper((unsigned char) *str);
915915
return;
916916
}
917917

src/interfaces/ecpg/pgtypeslib/datetime.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ PGTYPESdate_defmt_asc(date * d, char *fmt, char *str)
405405
reading_digit = 1;
406406
for (i = 0; str[i]; i++)
407407
{
408-
if (!isdigit(str[i]))
408+
if (!isdigit((unsigned char) str[i]))
409409
{
410410
reading_digit = 0;
411411
break;
@@ -495,22 +495,22 @@ PGTYPESdate_defmt_asc(date * d, char *fmt, char *str)
495495

496496
/* convert the whole string to lower case */
497497
for (i = 0; str_copy[i]; i++)
498-
str_copy[i] = (char) tolower(str_copy[i]);
498+
str_copy[i] = (char) tolower((unsigned char) str_copy[i]);
499499
}
500500

501501
/* look for numerical tokens */
502502
reading_digit = 0;
503503
token_count = 0;
504504
for (i = 0; i < strlen(str_copy); i++)
505505
{
506-
if (!isdigit(str_copy[i]) && reading_digit)
506+
if (!isdigit((unsigned char) str_copy[i]) && reading_digit)
507507
{
508508
/* the token is finished */
509509
token[token_count][1] = i - 1;
510510
reading_digit = 0;
511511
token_count++;
512512
}
513-
else if (isdigit(str_copy[i]) && !reading_digit)
513+
else if (isdigit((unsigned char) str_copy[i]) && !reading_digit)
514514
{
515515
/* we have found a token */
516516
token[token_count][0] = i;
@@ -565,7 +565,7 @@ PGTYPESdate_defmt_asc(date * d, char *fmt, char *str)
565565
{
566566
for (j = 0; j < PGTYPES_DATE_MONTH_MAXLENGTH; j++)
567567
{
568-
month_lower_tmp[j] = (char) tolower(list[i][j]);
568+
month_lower_tmp[j] = (char) tolower((unsigned char) list[i][j]);
569569
if (!month_lower_tmp[j])
570570
{
571571
/* properly terminated */

0 commit comments

Comments
 (0)