Fix fgetrune on systems where char is unsigned by default (ARM)

Store the result in an int and do the comparison.  This is always
safe without using strange constructs like "signed char".

wc(1) would go into an infinite loop when executed on an ARM
system.
This commit is contained in:
sin 2015-02-13 15:41:04 +00:00
parent 9f1f8d5dd8
commit d4830dba30

View File

@ -10,11 +10,13 @@ int
fgetrune(Rune *r, FILE *fp)
{
char buf[UTFmax];
int i;
int i = 0, c;
for (i = 0; i < UTFmax && (buf[i] = fgetc(fp)) != EOF && ++i ;)
while (i < UTFmax && (c = fgetc(fp)) != EOF) {
buf[i++] = c;
if (charntorune(r, buf, i) > 0)
break;
}
if (ferror(fp))
return -1;