Github user DaveBirdsall commented on a diff in the pull request:

    https://github.com/apache/incubator-trafodion/pull/257#discussion_r51169002
  
    --- Diff: core/sql/common/csconvert.cpp ---
    @@ -1275,3 +1279,45 @@ char * findStartOfChar( char *someByteInChar, char 
*startOfBuffer )
          rtnv-- ;
       return rtnv ;
     }
    +
    +/* A method to do character set conversion , using Glibc iconv */
    +static int charsetConvert(const char *srcCharset,const char 
*targetCharset,char *inputbuf, size_t inputlen, char *outbuf,size_t outlen)
    +{
    +  char **ptrin = &inputbuf;
    +  char **ptrout = &outbuf;
    +
    +  iconv_t cd;
    +  cd = iconv_open(targetCharset,srcCharset);
    +
    +  if (cd==0) 
    +    return -1;
    +
    +  if (iconv(cd,ptrin,(size_t*)&inputlen,ptrout,(size_t *)&outlen) == -1) 
    +  {
    +    //error occurs
    +    iconv_close(cd);
    +    return -1;
    +  }
    +
    +  iconv_close(cd);
    +  return outlen;
    +}
    +
    +/* convert gbk string into UTF8 */
    +int gbkToUtf8(char* gbkString, size_t gbklen, 
    +              char* result ,size_t outlen, bool addNullAtEnd)
    +{
    +   int originalOutlen = outlen;
    +   int finalLength = charsetConvert( "gbk","utf-8", gbkString, gbklen,  
result, outlen);
    +   
    +   if (finalLength == -1 ) 
    +     return -1;
    +   
    +   if ( addNullAtEnd )
    +   {
    +     if(originalOutlen >= finalLength )
    --- End diff --
    
    Wouldn't it need to be >, rather than >=? (Or does the caller leave an 
extra byte for null terminator?)


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to