[hackers] [sbase] Fix fgetrune on systems where char is unsigned by default (ARM) || sin

From: <git_AT_suckless.org>
Date: Fri, 13 Feb 2015 16:44:20 +0100 (CET)

commit 20211dba22e9d458b939c89be69d587669a5f074
Author: sin <sin_AT_2f30.org>
Date: Fri Feb 13 15:41:04 2015 +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.

diff --git a/libutf/fgetrune.c b/libutf/fgetrune.c
index 50fd355..8cd78c6 100644
--- a/libutf/fgetrune.c
+++ b/libutf/fgetrune.c
_AT_@ -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;
 
Received on Fri Feb 13 2015 - 16:44:20 CET

This archive was generated by hypermail 2.3.0 : Fri Feb 13 2015 - 16:48:10 CET