[GitHub] incubator-trafodion pull request #1220: [TRAFODION-2725] SQL types are REAL,...
Github user asfgit closed the pull request at: https://github.com/apache/incubator-trafodion/pull/1220 ---
[GitHub] incubator-trafodion pull request #1220: [TRAFODION-2725] SQL types are REAL,...
Github user SuJinpei commented on a diff in the pull request: https://github.com/apache/incubator-trafodion/pull/1220#discussion_r139306445 --- Diff: win-odbc64/odbcclient/drvr35/drvrglobal.cpp --- @@ -865,77 +865,18 @@ bool use_gcvt(double number, char* string, short size) bool double_to_char (double number, int precision, char* string, short size) { - char *buffer,*temp ; - bool rc = true; - - int decimal_spot, - sign, - count, - current_location = 0, - length; - - *string = 0; - - temp = _fcvt (number, precision, _spot, ) ; - length = strlen(temp); - if (length == 0) - { - return use_gcvt(number,string,size); - } - if (length > precision) - buffer = (char *) malloc (length + 3) ; - else - buffer = (char *) malloc (precision + 3) ; - - if (buffer == NULL) - return false; - -/* Add negative sign if required. */ - - if (sign) - buffer [current_location++] = '-' ; - -/* Place decimal point in the correct location. */ - - if (decimal_spot > 0) - { - strncpy ( [current_location], temp, decimal_spot) ; - buffer [decimal_spot + current_location] = '.' ; - strcpy ( [decimal_spot + current_location + 1], -[decimal_spot]) ; - } - else - { - buffer [current_location] = '.' ; - for(count = current_location; - count< abs(decimal_spot)+current_location; count++) - buffer [count + 1] = '0' ; - strcpy ( [count + 1], temp) ; - } +bool rc = false; +char format[16]; +char buf[MAX_DOUBLE_TO_CHAR_LEN]; - rSup(buffer); - length = strlen(buffer); - if (buffer[0] == '.' || (buffer[0] == '-' && buffer[1] == '.')) length++; +sprintf(format, "%%.%dlg", precision); +sprintf(buf, format, number); --- End diff -- @selvaganesang from original code logic, size should larger than strlen(buf). if we still want to return reasonable value though size less than strlen(buf), I think we should use other algorithm instead of snprintf. ---
[GitHub] incubator-trafodion pull request #1220: [TRAFODION-2725] SQL types are REAL,...
Github user selvaganesang commented on a diff in the pull request: https://github.com/apache/incubator-trafodion/pull/1220#discussion_r139188923 --- Diff: win-odbc64/odbcclient/drvr35/drvrglobal.cpp --- @@ -865,77 +865,18 @@ bool use_gcvt(double number, char* string, short size) bool double_to_char (double number, int precision, char* string, short size) { - char *buffer,*temp ; - bool rc = true; - - int decimal_spot, - sign, - count, - current_location = 0, - length; - - *string = 0; - - temp = _fcvt (number, precision, _spot, ) ; - length = strlen(temp); - if (length == 0) - { - return use_gcvt(number,string,size); - } - if (length > precision) - buffer = (char *) malloc (length + 3) ; - else - buffer = (char *) malloc (precision + 3) ; - - if (buffer == NULL) - return false; - -/* Add negative sign if required. */ - - if (sign) - buffer [current_location++] = '-' ; - -/* Place decimal point in the correct location. */ - - if (decimal_spot > 0) - { - strncpy ( [current_location], temp, decimal_spot) ; - buffer [decimal_spot + current_location] = '.' ; - strcpy ( [decimal_spot + current_location + 1], -[decimal_spot]) ; - } - else - { - buffer [current_location] = '.' ; - for(count = current_location; - count< abs(decimal_spot)+current_location; count++) - buffer [count + 1] = '0' ; - strcpy ( [count + 1], temp) ; - } +bool rc = false; +char format[16]; +char buf[MAX_DOUBLE_TO_CHAR_LEN]; - rSup(buffer); - length = strlen(buffer); - if (buffer[0] == '.' || (buffer[0] == '-' && buffer[1] == '.')) length++; +sprintf(format, "%%.%dlg", precision); +sprintf(buf, format, number); --- End diff -- There is a risk of writing out of range because precision is not checked to be within the buf size. Also, you need to allow the numbers to be truncated after a decimal even when there is no sufficient length passed by the caller. So size can be less than strlen(buf) as long as the fraction part alone is getting cut. ---
[GitHub] incubator-trafodion pull request #1220: [TRAFODION-2725] SQL types are REAL,...
Github user xwq commented on a diff in the pull request: https://github.com/apache/incubator-trafodion/pull/1220#discussion_r139059850 --- Diff: win-odbc64/odbcclient/drvr35/drvrglobal.cpp --- @@ -865,77 +865,18 @@ bool use_gcvt(double number, char* string, short size) bool double_to_char (double number, int precision, char* string, short size) { - char *buffer,*temp ; - bool rc = true; - - int decimal_spot, - sign, - count, - current_location = 0, - length; - - *string = 0; - - temp = _fcvt (number, precision, _spot, ) ; - length = strlen(temp); - if (length == 0) - { - return use_gcvt(number,string,size); - } - if (length > precision) - buffer = (char *) malloc (length + 3) ; - else - buffer = (char *) malloc (precision + 3) ; - - if (buffer == NULL) - return false; - -/* Add negative sign if required. */ - - if (sign) - buffer [current_location++] = '-' ; - -/* Place decimal point in the correct location. */ - - if (decimal_spot > 0) - { - strncpy ( [current_location], temp, decimal_spot) ; - buffer [decimal_spot + current_location] = '.' ; - strcpy ( [decimal_spot + current_location + 1], -[decimal_spot]) ; - } - else - { - buffer [current_location] = '.' ; - for(count = current_location; - count< abs(decimal_spot)+current_location; count++) - buffer [count + 1] = '0' ; - strcpy ( [count + 1], temp) ; - } +bool rc = false; +char format[16]; +char buf[MAX_DOUBLE_TO_CHAR_LEN]; - rSup(buffer); - length = strlen(buffer); - if (buffer[0] == '.' || (buffer[0] == '-' && buffer[1] == '.')) length++; +sprintf(format, "%%.%dlg", precision); +sprintf(buf, format, number); --- End diff -- snprint is better. ---
[GitHub] incubator-trafodion pull request #1220: [TRAFODION-2725] SQL types are REAL,...
Github user xwq commented on a diff in the pull request: https://github.com/apache/incubator-trafodion/pull/1220#discussion_r139059830 --- Diff: win-odbc64/odbcclient/drvr35/drvrglobal.cpp --- @@ -865,77 +865,18 @@ bool use_gcvt(double number, char* string, short size) bool double_to_char (double number, int precision, char* string, short size) { - char *buffer,*temp ; - bool rc = true; - - int decimal_spot, - sign, - count, - current_location = 0, - length; - - *string = 0; - - temp = _fcvt (number, precision, _spot, ) ; - length = strlen(temp); - if (length == 0) - { - return use_gcvt(number,string,size); - } - if (length > precision) - buffer = (char *) malloc (length + 3) ; - else - buffer = (char *) malloc (precision + 3) ; - - if (buffer == NULL) - return false; - -/* Add negative sign if required. */ - - if (sign) - buffer [current_location++] = '-' ; - -/* Place decimal point in the correct location. */ - - if (decimal_spot > 0) - { - strncpy ( [current_location], temp, decimal_spot) ; - buffer [decimal_spot + current_location] = '.' ; - strcpy ( [decimal_spot + current_location + 1], -[decimal_spot]) ; - } - else - { - buffer [current_location] = '.' ; - for(count = current_location; - count< abs(decimal_spot)+current_location; count++) - buffer [count + 1] = '0' ; - strcpy ( [count + 1], temp) ; - } +bool rc = false; +char format[16]; +char buf[MAX_DOUBLE_TO_CHAR_LEN]; --- End diff -- need initialize. **_char buf[MAX_DOUBLE_TO_CHAR_LEN] = {0};_** ---
[GitHub] incubator-trafodion pull request #1220: [TRAFODION-2725] SQL types are REAL,...
GitHub user SuJinpei opened a pull request: https://github.com/apache/incubator-trafodion/pull/1220 [TRAFODION-2725] SQL types are REAL, FLOAT, and DOUBLE. Some values are inserted, a stack overflow occurs when SQLGetData is executed. **_root cause:_** write stack variable out of range. unsigned long ODBC::ConvertSQLToC(, targetLength) { ... CHARcTmpBuf[132]; ... double_to_char (dTmp, FLT_DIG + 1, cTmpBuf, targetLength) // when targetLength > 132, the stack will be broken. ... } **_fixed by:_**limit the max size to sizeof(cTmpBuf) **_test result:_**run coast to check, no new issue introduced. You can merge this pull request into a Git repository by running: $ git pull https://github.com/SuJinpei/incubator-trafodion trafodion-2725 Alternatively you can review and apply these changes as the patch at: https://github.com/apache/incubator-trafodion/pull/1220.patch To close this pull request, make a commit to your master/trunk branch with (at least) the following in the commit message: This closes #1220 commit 73548715fd95856d34724bb7c2f4b44e3c3b7f3d Author: SuJinpei <873118...@qq.com> Date: 2017-08-25T07:45:19Z fix TRAFODION-2725 commit b6513da5a82f9161457ae854a30cab2026b5c865 Author: SuJinpei <873118...@qq.com> Date: 2017-08-30T06:00:17Z fix TRAFODION-2725 --- 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 infrastruct...@apache.org or file a JIRA ticket with INFRA. ---