Dead code in samples

From: Igor Bukanov (igor@icesoft.no)
Date: Tue Sep 04 2001 - 11:21:59 EDT


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



This archive was generated by hypermail 2.1.2 : Tue Sep 04 2001 - 12:08:09 EDT