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, &decimal_spot, &sign) ;
    -   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 (&buffer [current_location], temp, decimal_spot) ;
    -           buffer [decimal_spot + current_location] = '.' ;
    -           strcpy (&buffer [decimal_spot + current_location + 1],
    -                                   &temp [decimal_spot]) ;
    -   }
    -   else
    -   {
    -           buffer [current_location] = '.' ;
    -           for(count = current_location;
    -                   count< abs(decimal_spot)+current_location; count++)
    -                   buffer [count + 1] = '0' ;
    -           strcpy (&buffer [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.


---

Reply via email to