[sqlapi-announce] SQLAPI++ library 4.0.1 bugfix (Fixed SAString::SetUTF16Chars method)

  • From: Sergey Chumakov <support@xxxxxxxxxx>
  • To: sqlapi-announce@xxxxxxxxxxxxx
  • Date: Sun, 24 Jun 2012 18:17:42 +0300

2012-06-24

-- General: Fixed SAString::SetUTF16Chars method (avoid crash when the source string is NULL). -- General: Avoided double conversion of UTF-8 and UTF-16 data (SA_STRING_EXT required, thanks Christian Schmitz).

Use attached diff file for 4.0.1 sources patching.

--
Best regards,
Sergey Chumakov, SQLAPI++ development team
















*** D:/yas/Local Settings/Temp/TCV24822.tmp/SQLAPI.1.133.cpp    Thu May 31 
19:21:26 2012
--- D:/src/SQLAPI/SQLAPI/src/SQLAPI.cpp Sun Jun 24 17:28:46 2012
***************
*** 2305,2314 ****
--- 2305,2320 ----
        return GetData()->pUTF8Data->nDataLength;
  }
  
  void SAString::SetUTF8Chars(const char* szSrc, size_t nSrcLen/* = SIZE_MAX*/)
  {
+       if( NULL == szSrc )
+       {
+               Empty();
+               return;
+       }
+ 
        if( SIZE_MAX == nSrcLen )
                nSrcLen = NULL == szSrc ? 0:strlen(szSrc);
  
        if( 0 == nSrcLen )
        {
***************
*** 2333,2342 ****
--- 2338,2355 ----
        utf8_to_wchar(szSrc, nSrcLen, m_pchData, wcLen, UTF8_IGNORE_ERROR);
  #endif
        GetData()->nDataLength = wcLen;
        m_pchData[wcLen] = '\0';
        GetData()->nBinaryDataLengthDiff = 0;
+ 
+ #ifdef SA_STRING_EXT
+       pData->pUTF8Data = (SAStringConvertedData *)
+               new unsigned char[sizeof(SAStringConvertedData) + 
(nSrcLen+1)*sizeof(char)];
+       memcpy(pData->pUTF8Data->data(), szSrc, nSrcLen);
+       pData->pUTF8Data->nDataLength = nSrcLen;
+       pData->pUTF8Data->data()[nSrcLen] = '\0';
+ #endif
  }
  
  const void *SAString::GetUTF16Chars() const
  {
        if( IsEmpty() )
***************
*** 2381,2393 ****
--- 2394,2419 ----
  #endif
  }
  
  void SAString::SetUTF16Chars(const void* szSrc, size_t nSrcLen/* = SIZE_MAX*/)
  {
+       if( NULL == szSrc )
+       {
+               Empty();
+               return;
+       }
+ 
  #ifdef SQLAPI_WIN32
        if( SIZE_MAX == nSrcLen )
                nSrcLen = wcslen((const wchar_t*)szSrc);
+ 
+       if( 0 == nSrcLen )
+       {
+               Empty();
+               return;
+       }
+ 
        *this = SAString((const wchar_t*)szSrc, nSrcLen);
  #else
        if( SIZE_MAX == nSrcLen )
                nSrcLen = NULL == szSrc ? 0:utf16_strlen((UTF16*)szSrc);
  
***************
*** 2407,2416 ****
--- 2433,2450 ----
        utf16_to_utf32(&in, nSrcLen, (UTF32*)m_pchData, wcLen, 
UTF16_IGNORE_ERROR);
  
        GetData()->nDataLength = wcLen;
        m_pchData[wcLen] = '\0';
        GetData()->nBinaryDataLengthDiff = 0;
+ 
+ #ifdef SA_STRING_EXT
+       pData->pUTF16Data = (SAStringUtf16Data *)
+               new unsigned char[sizeof(SAStringUtf16Data) + 
(nSrcLen+1)*sizeof(UTF16)];
+       memcpy(pData->pUTF16Data->data(), szSrc, nSrcLen*sizeof(UTF16));
+       pData->pUTF16Data->nDataLength = nSrcLen;
+       pData->pUTF16Data->data()[nSrcLen] = '\0';
+ #endif
  #endif
  }
  #else // !SA_UNICODE
  
  static void ConvertToWideChars(SAStringData *pData)

Other related posts:

  • » [sqlapi-announce] SQLAPI++ library 4.0.1 bugfix (Fixed SAString::SetUTF16Chars method) - Sergey Chumakov