fix the pull-request comments for jira1720
Project: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/commit/12a0c3e4 Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/tree/12a0c3e4 Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/diff/12a0c3e4 Branch: refs/heads/master Commit: 12a0c3e4006d9c2b2cf9e62f23121b27ddee17c9 Parents: d51d201 Author: Cloud User <[email protected]> Authored: Tue Jan 12 14:43:03 2016 +0000 Committer: Cloud User <[email protected]> Committed: Tue Jan 12 14:43:03 2016 +0000 ---------------------------------------------------------------------- core/sql/common/csconvert.cpp | 10 ++++++++-- core/sql/common/csconvert.h | 2 +- core/sql/exp/exp_conv.cpp | 5 +++-- 3 files changed, 12 insertions(+), 5 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/12a0c3e4/core/sql/common/csconvert.cpp ---------------------------------------------------------------------- diff --git a/core/sql/common/csconvert.cpp b/core/sql/common/csconvert.cpp index b0d21af..f94ec2a 100644 --- a/core/sql/common/csconvert.cpp +++ b/core/sql/common/csconvert.cpp @@ -1304,16 +1304,22 @@ int gbk2utf8(char *inbuf,size_t inlen,char *outbuf,size_t outlen) return code_convert("gbk","utf-8",inbuf,inlen,outbuf,outlen); } +/* convert gbk string into UTF8 */ int gbkToUtf8(char* gbkString, size_t gbklen, char* result ,size_t outlen, int addNullAtEnd) { - + int originalOutlen = outlen; int finalLength = gbk2utf8 ( gbkString, gbklen, result, outlen); if (finalLength == -1 ) return 0; + //the result is allocated with lenght originalOutlen + 1 + //so no overrun is possible if ( addNullAtEnd > 0 ) - result[finalLength] = 0; + { + if(originalOutlen >= finalLength ) + result[finalLength] = 0; + } return finalLength; } http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/12a0c3e4/core/sql/common/csconvert.h ---------------------------------------------------------------------- diff --git a/core/sql/common/csconvert.h b/core/sql/common/csconvert.h index 57fec71..810fae5 100644 --- a/core/sql/common/csconvert.h +++ b/core/sql/common/csconvert.h @@ -108,7 +108,7 @@ int UTF16ToLocale( const enum cnv_version version, NA_EIDPROC int gbkToUtf8(char* gbkString, size_t gbklen, - char* result ,size_t outlen, int addNullAtEnd=FALSE); + char* result ,size_t outlen, bool addNullAtEnd=FALSE); /* * LocaleCharToUCS4() converts the FIRST char in the input string to its http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/12a0c3e4/core/sql/exp/exp_conv.cpp ---------------------------------------------------------------------- diff --git a/core/sql/exp/exp_conv.cpp b/core/sql/exp/exp_conv.cpp index 015ec0f..319727f 100644 --- a/core/sql/exp/exp_conv.cpp +++ b/core/sql/exp/exp_conv.cpp @@ -9331,8 +9331,9 @@ convDoIt(char * source, if (convLen > 0) { copyLen = (convLen< targetLen) ? convLen: targetLen; str_cpy_all(target, targetbuf, copyLen); - // if (convLen > targetLen) - + //if the target length is not enough, instead of truncate, raise a SQL Error + if (convLen > targetLen) + ExRaiseSqlError(heap, diagsArea, EXE_STRING_OVERFLOW); } else { // LCOV_EXCL_START
