Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitdb4a5cf

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 largeinput, or lose precision for a very small input. Adopt the methodologythat's been in use in the equivalent backend code for a long time.Per private report from Bas van Schaik. Back-patch to all supportedbranches.
1 parent2287b87 commitdb4a5cf

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(doubled,numeric*dst)
14991500
{
1500-
charbuffer[100];
1501+
charbuffer[DBL_DIG+100];
15011502
numeric*tmp;
15021503
inti;
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)

[8]ページ先頭

©2009-2025 Movatter.jp