Re: using arrays within structure in ECPG

From: Ashutosh Bapat <ashutosh(dot)bapat(at)enterprisedb(dot)com>
To: Ashutosh Bapat <ashutosh(dot)bapat(at)enterprisedb(dot)com>, Michael Meskes <meskes(at)postgresql(dot)org>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: using arrays within structure in ECPG
Date: 2014-04-02 12:19:03
Message-ID: CAFjFpReujo8H_KeHF3k1Zbk7LL7AX2cQ2d_r_8R6fnDStpD1kA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

I have one more doubt, regarding offsets.

In ECPGdump_a_simple() we have code
if (siz == NULL || strlen(siz) == 0 || strcmp(arrsize, "0") == 0 ||
strcmp(arrsize, "1") == 0)
fprintf(o, "\n\t%s,%s,(long)%s,(long)%s,%s, ", get_type(type),
variable, varcharsize, arrsize, offset);
else
fprintf(o, "\n\t%s,%s,(long)%s,(long)%s,%s, ", get_type(type),
variable, varcharsize, arrsize, siz);

If the caller has passed siz, it means that this variable is part of the a
structure. Remember in dump_variables(), this function is called with
struct_sizeof = NULL. So, once we know that siz != NULL and strlen(siz) !=
0, it's evident that the simple variable we are dumping is part of a
structure and hence we should be using "siz" instead of "offset". Why then
we still check arrsize?

In a case, where we are dumping a pointer to a structure, this code dumps
each member with offset = size of that member, thus again corrupting
memory, if there are more than one rows being saved through pointer.

On Wed, Apr 2, 2014 at 3:10 PM, Michael Meskes <meskes(at)postgresql(dot)org>wrote:

> On Wed, Apr 02, 2014 at 09:33:15AM +0530, Ashutosh Bapat wrote:
> > So, you are saying that we should try to catch such errors and report
> > during pre-compile time. That's better than silently corrupting the data.
>
> Well, I think this goes without saying.
>
> Michael
> --
> Michael Meskes
> Michael at Fam-Meskes dot De, Michael at Meskes dot (De|Com|Net|Org)
> Michael at BorussiaFan dot De, Meskes at (Debian|Postgresql) dot Org
> Jabber: michael.meskes at gmail dot com
> VfL Borussia! Força Barça! Go SF 49ers! Use Debian GNU/Linux, PostgreSQL
>

--
Best Wishes,
Ashutosh Bapat
EnterpriseDB Corporation
The Postgres Database Company

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Etsuro Fujita 2014-04-02 12:25:43 Re: inherit support for foreign tables
Previous Message Michael Paquier 2014-04-02 11:59:03 Re: Including replication slot data in base backups