Re: [patch]overallocate memory for curly braces in array_out

From: Keiichi Hirobe <chalenge(dot)akane(at)gmail(dot)com>
To: tgl(at)sss(dot)pgh(dot)pa(dot)us
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [patch]overallocate memory for curly braces in array_out
Date: 2018-09-26 12:04:51
Message-ID: CAH=EFxEc+V=F-dO6HAPnbaZSZzqjkEJywkcxCfp=Ki=VfDEB8g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

Thanks for the reply.

I am not sure whether to fix another bug, but I fixed and I attached a new
patch,
please check it.

Please note that I inserted a line for updating "overall_length" at line
1185.

I checked below case.

select ARRAY[ARRAY[1,2,3],ARRAY[4,5,6]]; (regular case)
select '[3:4][2:4]={{1,2,3},{4,5,6}}'::_int4; (needdims case)
select ARRAY['a"bc','def']; (needquote case)

Cheers,
Keiichi Hirobe

2018年9月24日(月) 23:46 Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>:

> Keiichi Hirobe <chalenge(dot)akane(at)gmail(dot)com> writes:
> > Attached is a patch that fixes a bug
> > for miscounting total number of curly braces in output string in
> array_out.
>
> Wow, good catch!
>
> Testing this, I found there's a second way in which the space calculation
> is off: it always allocated one more byte than required, as a result of
> counting one more comma than is really required. That's not nearly as
> significant as the curly-brace miscount, but it still got in the way of
> doing this:
>
> *** 1234,1239 ****
> --- 1243,1251 ----
> #undef APPENDSTR
> #undef APPENDCHAR
>
> + /* Assert that we calculated the string length accurately */
> + Assert(overall_length == (p - retval + 1));
> +
> pfree(values);
> pfree(needquotes);
>
>
> which seemed to me like a good idea now that we know this code isn't
> so perfect as all that.
>
> Will push shortly.
>
> regards, tom lane
>

Attachment Content-Type Size
array_out_bugfix2.patch application/octet-stream 1.1 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Eisentraut 2018-09-26 12:38:25 Re: transction_timestamp() inside of procedures
Previous Message Peter Eisentraut 2018-09-26 11:36:05 Re: Implementing SQL ASSERTION