bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

striconv fix


From: Bruno Haible
Subject: striconv fix
Date: Tue, 16 Jan 2007 04:24:05 +0100 (MET)
User-agent: KMail/1.5.4

Hi,

The striconv module may fail to recognize a conversion error if the
iconv() implementation is NetBSD's iconv or IRIX iconv, and if the
initial guess for the output buffer size turns out to be too small.
I'm applying this fix.

2007-01-15  Bruno Haible  <address@hidden>

        * lib/striconv.c (str_cd_iconv): Use the first algorithm if iconv is
        not from GNU libiconv or GNU libc.

diff -c -3 -r1.6 striconv.c
*** lib/striconv.c      13 Jan 2007 14:48:51 -0000      1.6
--- lib/striconv.c      16 Jan 2007 03:19:31 -0000
***************
*** 192,198 ****
       to a trailing NUL byte in the output.  But not for UTF-7.  So that this
       function is usable for UTF-7, we have to exclude the NUL byte from the
       conversion and add it by hand afterwards.  */
! # if PROBABLY_SLOWER
  
    char *result = NULL;
    size_t length;
--- 192,205 ----
       to a trailing NUL byte in the output.  But not for UTF-7.  So that this
       function is usable for UTF-7, we have to exclude the NUL byte from the
       conversion and add it by hand afterwards.  */
! # if !defined _LIBICONV_VERSION && !defined __GLIBC__
!   /* Irix iconv() inserts a NUL byte if it cannot convert.
!      NetBSD iconv() inserts a question mark if it cannot convert.
!      Only GNU libiconv and GNU libc are known to prefer to fail rather
!      than doing a lossy conversion.  For other iconv() implementations,
!      we have to look at the number of irreversible conversions returned;
!      but this information is lost when iconv() returns for an E2BIG reason.
!      Therefore we cannot use the second, faster algorithm.  */
  
    char *result = NULL;
    size_t length;
***************
*** 225,231 ****
    return final_result;
  
  # else
! 
    char *result;
    size_t result_size;
    size_t length;
--- 232,241 ----
    return final_result;
  
  # else
!   /* This algorithm is likely faster than the one above.  But it may produce
!      iconv() returns for an E2BIG reason, when the output size guess is too
!      small.  Therefore it can only be used when we don't need the number of
!      irreversible conversions performed.  */
    char *result;
    size_t result_size;
    size_t length;
***************
*** 299,315 ****
            else
              goto failed;
          }
- # if !defined _LIBICONV_VERSION && !defined __GLIBC__
-       /* Irix iconv() inserts a NUL byte if it cannot convert.
-          NetBSD iconv() inserts a question mark if it cannot convert.
-          Only GNU libiconv and GNU libc are known to prefer to fail rather
-          than doing a lossy conversion.  */
-       else if (res > 0)
-         {
-           errno = EILSEQ;
-           goto failed;
-         }
- # endif
        else
          break;
        }
--- 309,314 ----





reply via email to

[Prev in Thread] Current Thread [Next in Thread]