From d4830dba302a95f970f42e04e745658aa367c8a0 Mon Sep 17 00:00:00 2001 From: sin Date: Fri, 13 Feb 2015 15:41:04 +0000 Subject: [PATCH] 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. --- libutf/fgetrune.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libutf/fgetrune.c b/libutf/fgetrune.c index 50fd355..8cd78c6 100644 --- 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;