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

Commit3df4fa6

Browse files
committed
Fix memory allocation for output of hstore type.
Per "maosen.zhang" <maosen.zhang@alibaba-inc.com> report.
1 parent96e218a commit3df4fa6

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

‎contrib/hstore/hstore_io.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* $PostgreSQL: pgsql/contrib/hstore/hstore_io.c,v 1.9 2009/03/15 22:05:17 tgl Exp $
2+
* $PostgreSQL: pgsql/contrib/hstore/hstore_io.c,v 1.10 2009/04/02 17:57:05 teodor Exp $
33
*/
44
#include"postgres.h"
55

@@ -446,7 +446,8 @@ hstore_out(PG_FUNCTION_ARGS)
446446
{
447447
HStore*in=PG_GETARG_HS(0);
448448
intbuflen,
449-
i;
449+
i,
450+
nnulls=0;
450451
char*out,
451452
*ptr;
452453
char*base=STRPTR(in);
@@ -460,8 +461,15 @@ hstore_out(PG_FUNCTION_ARGS)
460461
PG_RETURN_CSTRING(out);
461462
}
462463

463-
buflen= (4/* " */+2/* => */+2/* , */ )*in->size+
464-
2/* esc */* (VARSIZE(in)-CALCDATASIZE(in->size,0));
464+
for (i=0;i<in->size;i++)
465+
if (entries[i].valisnull)
466+
nnulls++;
467+
468+
buflen= (4/* " */+2/* => */ )* (in->size-nnulls )+
469+
(2/* " */+2/* => */+4/* NULL */ )*nnulls+
470+
2/* , */* (in->size-1 )+
471+
2/* esc */* (VARSIZE(in)-CALCDATASIZE(in->size,0))+
472+
1/* \0 */;
465473

466474
out=ptr=palloc(buflen);
467475
for (i=0;i<in->size;i++)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp