RE: Dead code in samples

From: Marco Cimarosti (marco.cimarosti@essetre.it)
Date: Tue Sep 04 2001 - 12:34:27 EDT


Igor Bukanov wrote:
> 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;
> }

I'd agree with Igor. I also notice that the code in the last "else" seems
rather doing "UTF-8 to UTF->>>16<<<", so I guess that it has been forgotten
in from another piece of code.

_ Marco



This archive was generated by hypermail 2.1.2 : Tue Sep 04 2001 - 13:46:21 EDT