It seems that a sample UTF32 to UTF8 conversion in
http://www.unicode.org/Public/PROGRAMS/CVTUTF/ConvertUTF.c
contains dead code. In particular, the ConvertUTF8toUTF32 method has:

                if (ch <= UNI_MAX_UTF32) {
                        *target++ = ch;
                } else if (ch > UNI_MAX_UTF32) {
                        *target++ = UNI_REPLACEMENT_CHAR;
                } else {
                        if (target + 1 >= targetEnd) {
                                result = targetExhausted; break;
                        }
                        ch -= halfBase;
                        *target++ = (ch >> halfShift) + UNI_SUR_HIGH_START;
                        *target++ = (ch & halfMask) + UNI_SUR_LOW_START;
                }

Here the second if condition is exactly opposite to the first if 
condition so the the code after the last else is never executed.

Should it be just replaced by
                if (ch <= UNI_MAX_UTF32) {
                        *target++ = ch;
                } else {
                        *target++ = UNI_REPLACEMENT_CHAR;
                }
?

Regards, Igor


Reply via email to