Re: [patch]overallocate memory for curly braces in array_out - Mailing list pgsql-hackers

From Tom Lane
Subject Re: [patch]overallocate memory for curly braces in array_out
Date
Msg-id 727.1537800402@sss.pgh.pa.us
Whole thread Raw
In response to [patch]overallocate memory for curly braces in array_out  (Keiichi Hirobe <chalenge.akane@gmail.com>)
Responses Re: [patch]overallocate memory for curly braces in array_out
List pgsql-hackers
Keiichi Hirobe <chalenge.akane@gmail.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


pgsql-hackers by date:

Previous
From: Joe Conway
Date:
Subject: Re: doc - add missing documentation for "acldefault"
Next
From: Michael Paquier
Date:
Subject: Re: New function pg_stat_statements_reset_query() to resetstatistics of a specific query