Thanks, fix attached and applied

---------------------------------------------------------------------------

Eugen Nedelcu wrote:
> In function format_numericsep() you have:
> 
> new_str = pg_local_malloc(len_numericseps(my_str) + 1),
> 
> instead of:
> 
> new_str = pg_local_malloc(len_with_numericsep(my_str) + 1)
> 
> Another bug is in function len_numericseps(). This apear for querys 
> like:
> 
> select NULL::numeric; or
> select * from table_with_numeric_fields; where one of numeric fields
> have null values;
> 
> For such values, len_numericseps returns -1, instead of 0.
> 
> Instead of:
> 
> if (int_len % groupdigits != 0)
>     sep_len = int_len / groupdigits;
> else
>     sep_len = int_len / groupdigits - 1;
>     
> you must have:
> 
> if (int_len % groupdigits != 0 || int_len == 0)
>     sep_len = int_len / groupdigits;
> else
>     sep_len = int_len / groupdigits - 1;
> 
> Best Regards,
> Eugen
> 

-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073
Index: src/bin/psql/print.c
===================================================================
RCS file: /cvsroot/pgsql/src/bin/psql/print.c,v
retrieving revision 1.69
diff -c -c -r1.69 print.c
*** src/bin/psql/print.c        14 Jul 2005 21:12:41 -0000      1.69
--- src/bin/psql/print.c        18 Jul 2005 17:16:37 -0000
***************
*** 68,77 ****
        int int_len = integer_digits(my_str), sep_len;
        int     groupdigits = atoi(grouping);
  
!       if (int_len % groupdigits != 0)
!               sep_len = int_len / groupdigits;
        else
!               sep_len = int_len / groupdigits - 1;    /* no leading separator 
*/
  
        return sep_len * strlen(thousands_sep) -
                   strlen(".") + strlen(decimal_point);
--- 68,78 ----
        int int_len = integer_digits(my_str), sep_len;
        int     groupdigits = atoi(grouping);
  
!       if (int_len == 0)
!               sep_len = 0;
        else
!               /* Don't count a leading separator */
!               sep_len = int_len / groupdigits - (int_len % groupdigits == 0);
  
        return sep_len * strlen(thousands_sep) -
                   strlen(".") + strlen(decimal_point);
***************
*** 93,99 ****
        if (my_str[0] == '-')
                my_str++;
        
!       new_str = pg_local_malloc(len_numericseps(my_str) + 1);
  
        leading_digits = (int_len % groupdigits != 0) ?
                                         int_len % groupdigits : groupdigits;
--- 94,100 ----
        if (my_str[0] == '-')
                my_str++;
        
!       new_str = pg_local_malloc(len_with_numericsep(my_str) + 1);
  
        leading_digits = (int_len % groupdigits != 0) ?
                                         int_len % groupdigits : groupdigits;
---------------------------(end of broadcast)---------------------------
TIP 4: Have you searched our list archives?

               http://archives.postgresql.org

Reply via email to