Content-Length: 281573 | pFad | http://github.com/postgrespro/postgres_cluster/commit/db4a5cfc76206db82d0b929d96c53de229ef1aa4

10 Use "g" not "f" format in ecpg's PGTYPESnumeric_from_double(). · postgrespro/postgres_cluster@db4a5cf · GitHub
Skip to content

Commit db4a5cf

Browse files
committed
Use "g" not "f" format in ecpg's PGTYPESnumeric_from_double().
The previous coding could overrun the provided buffer size for a very large input, or lose precision for a very small input. Adopt the methodology that's been in use in the equivalent backend code for a long time. Per private report from Bas van Schaik. Back-patch to all supported branches.
1 parent 2287b87 commit db4a5cf

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/interfaces/ecpg/pgtypeslib/numeric.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include "postgres_fe.h"
44
#include <ctype.h>
5+
#include <float.h>
56
#include <limits.h>
67

78
#include "extern.h"
@@ -1497,11 +1498,11 @@ PGTYPESnumeric_copy(numeric *src, numeric *dst)
14971498
int
14981499
PGTYPESnumeric_from_double(double d, numeric *dst)
14991500
{
1500-
char buffer[100];
1501+
char buffer[DBL_DIG + 100];
15011502
numeric *tmp;
15021503
int i;
15031504

1504-
if (sprintf(buffer, "%f", d) == 0)
1505+
if (sprintf(buffer, "%.*g", DBL_DIG, d) <= 0)
15051506
return -1;
15061507

15071508
if ((tmp = PGTYPESnumeric_from_asc(buffer, NULL)) == NULL)

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/postgrespro/postgres_cluster/commit/db4a5cfc76206db82d0b929d96c53de229ef1aa4

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy