You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-dev@xerces.apache.org by Wolter Eldering <Wo...@lifeline.nl> on 2000/07/20 16:39:45 UTC

bug in IconvLCPTranscoder::transcode

The method IconvLCPTranscoder::transcode fails if the toTranscode parameter
contains invalid characters.
 
size_t wcstombs (char *dest, const wchar_t *src, size_t n);
RETURN VALUE
       The wcstombs function returns the number of bytes that make up the
converted part of multibyte sequence, not
       including the terminating null byte.  If a wide character was
encountered  which  could  not  be  converted,
       (size_t)(-1) is returned.

this return value is not correctly handled in:
 
xerces-c-src_1_2_0/src/util/Transcoders/Iconv/IconvTransService.cpp
    char* IconvLCPTranscoder::transcode(const XMLCh* const toTranscode)
    {
        ...
        // Calc the needed size.
      const size_t neededLen = ::wcstombs(NULL, wideCharBuf, 0);
        if (neededLen == 0)
        {
            delete [] allocatedArray;
            return 0;
        }
 
        retVal = new char[neededLen + 1];

        ...
    }
 
 
        to handle the line:
            if (neededLen == 0)
        could be changed into:
            if (0 == neededLen || (size_t)(-1) == neededLen)
 
        
 
 
Wolter Eldering
Senior Development Engineer
LifeLine Network bv