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

Commitd69c781

Browse files
committed
Fix pg_strtof() to not crash on NULL endptr.
We had managed not to notice this simple oversight because noneof our calls exercised the case --- until commit8f42718.That led to pg_dump crashing on any platform that uses this code(currently Cygwin and Mingw).Even though there's no immediate bug in the back branches, backpatch,because a non-POSIX-compliant strtof() substitute is trouble waitingto happen for extensions or future back-patches.Diagnosed-by: Alexander Lakhin <exclusion@gmail.com>Author: Tom Lane <tgl@sss.pgh.pa.us>Discussion:https://postgr.es/m/339b3902-4e98-4e31-a744-94e43b7b9292@gmail.comBackpatch-through: 13
1 parentee78823 commitd69c781

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

‎src/port/strtof.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,18 @@ pg_strtof(const char *nptr, char **endptr)
3131
{
3232
intcaller_errno=errno;
3333
floatfresult;
34+
char*myendptr;
3435

3536
errno=0;
36-
fresult= (strtof) (nptr,endptr);
37+
fresult= (strtof) (nptr,&myendptr);
38+
if (endptr)
39+
*endptr=myendptr;
3740
if (errno)
3841
{
3942
/* On error, just return the error to the caller. */
4043
returnfresult;
4144
}
42-
elseif ((*endptr==nptr)||isnan(fresult)||
45+
elseif ((myendptr==nptr)||isnan(fresult)||
4346
((fresult >=FLT_MIN||fresult <=-FLT_MIN)&& !isinf(fresult)))
4447
{
4548
/*
@@ -53,7 +56,8 @@ pg_strtof(const char *nptr, char **endptr)
5356
else
5457
{
5558
/*
56-
* Try again. errno is already 0 here.
59+
* Try again. errno is already 0 here, and we assume that the endptr
60+
* won't be any different.
5761
*/
5862
doubledresult=strtod(nptr,NULL);
5963

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp