Bug printing string where the 128th char is multibyte

Eduardo D'Avila erdavila@gmail.com
Mon Jan 4 23:25:00 GMT 2010


Using the %s  didn't solve the problem:


erdavila@antares ~/perl/feedbacks
$ cat BUG.c
#include <stdio.h>

int main() {
        const char * str =
                "0123456789"    //   0 -   9
                "0123456789"    //  10 -  19
                "0123456789"    //  20 -  29
                "0123456789"    //  30 -  39
                "0123456789"    //  40 -  49
                "0123456789"    //  50 -  59
                "0123456789"    //  60 -  69
                "0123456789"    //  70 -  79
                "0123456789"    //  80 -  89
                "0123456789"    //  90 -  99
                "0123456789"    // 100 - 109
                "0123456789"    // 110 - 119
                "0123456ç89"    // 120 - 127
                ;

        printf("%s", str);

        return 0;
}

erdavila@antares ~/perl/feedbacks
$ gcc -Wall BUG.c  -o BUG

erdavila@antares ~/perl/feedbacks
$ ./BUG
ç89



Eduardo R. D'Avila



2010/1/4 Eric Blake <ebb9@byu.net>:
> Eduardo D'Avila <erdavila <at> gmail.com> writes:
>
>> I've found a bug that happens when the 128th (index 127 on a 0-based
>> string) char of a string is a multibyte char. When I print such
>> string, only the multibyte char and the chars after it are displayed.
>
> What you've found is a bug in your own program, at lesat for the BUG.c version
> of your report.
>
> http://cygwin.com/ml/cygwin/2010-01/msg00100.html
>
> Try 'printf ("%s",str)' rather than 'printf (str)' to see the difference.  And
> why 128 bytes into the string?  That's the cutoff of where gcc optimizes a
> printf without % into a puts.
>
> --
> Eric Blake
> --
> Problem reports:       http://cygwin.com/problems.html
> FAQ:                   http://cygwin.com/faq/
> Documentation:         http://cygwin.com/docs.html
> Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
>
>

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple



More information about the Cygwin mailing list