commit d4830dba302a95f970f42e04e745658aa367c8a0
parent 9f1f8d5dd877fe2e0508b7be38fd6d054b4e0ab8
Author: sin <sin@2f30.org>
Date: Fri, 13 Feb 2015 15:41:04 +0000
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.
Diffstat:
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/libutf/fgetrune.c b/libutf/fgetrune.c
@@ -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;