Skip to content

Commit adeede1

Browse files
committed
Fix numiericsep length computations.
Eugen Nedelcu
1 parent df38d79 commit adeede1

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/bin/psql/print.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright (c) 2000-2005, PostgreSQL Global Development Group
55
*
6-
* $PostgreSQL: pgsql/src/bin/psql/print.c,v 1.69 2005/07/14 21:12:41 momjian Exp $
6+
* $PostgreSQL: pgsql/src/bin/psql/print.c,v 1.70 2005/07/18 18:58:45 momjian Exp $
77
*/
88
#include "postgres_fe.h"
99
#include "common.h"
@@ -68,10 +68,11 @@ len_numericseps(const char *my_str)
6868
int int_len = integer_digits(my_str), sep_len;
6969
int groupdigits = atoi(grouping);
7070

71-
if (int_len % groupdigits != 0)
72-
sep_len = int_len / groupdigits;
71+
if (int_len == 0)
72+
sep_len = 0;
7373
else
74-
sep_len = int_len / groupdigits - 1; /* no leading separator */
74+
/* Don't count a leading separator */
75+
sep_len = int_len / groupdigits - (int_len % groupdigits == 0);
7576

7677
return sep_len * strlen(thousands_sep) -
7778
strlen(".") + strlen(decimal_point);
@@ -93,7 +94,7 @@ format_numericsep(char *my_str)
9394
if (my_str[0] == '-')
9495
my_str++;
9596

96-
new_str = pg_local_malloc(len_numericseps(my_str) + 1);
97+
new_str = pg_local_malloc(len_with_numericsep(my_str) + 1);
9798

9899
leading_digits = (int_len % groupdigits != 0) ?
99100
int_len % groupdigits : groupdigits;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy