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:
parent
9f1f8d5dd8
commit
d4830dba30
|
@ -10,11 +10,13 @@ int
|
||||||
fgetrune(Rune *r, FILE *fp)
|
fgetrune(Rune *r, FILE *fp)
|
||||||
{
|
{
|
||||||
char buf[UTFmax];
|
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)
|
if (charntorune(r, buf, i) > 0)
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
if (ferror(fp))
|
if (ferror(fp))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user