BUG #1774: ecpg preprocessor produces a wrong varchar struct - Mailing list pgsql-bugs

From Dirk Jagdmann
Subject BUG #1774: ecpg preprocessor produces a wrong varchar struct
Date
Msg-id 20050718164017.2F523F0AC6@svr2.postgresql.org
Whole thread Raw
List pgsql-bugs
The following bug has been logged online:

Bug reference:      1774
Logged by:          Dirk Jagdmann
Email address:      doj@cubic.org
PostgreSQL version: 8.0.3
Operating system:   i686 Linux 2.6
Description:        ecpg preprocessor produces a wrong varchar struct
Details:

The ecpg preprocessor produces wrong code which does not compile.

--- input.pgc ---
int main()
{
  EXEC SQL BEGIN DECLARE SECTION;
  VARCHAR v;
  EXEC SQL END DECLARE SECTION;
  return 0;
}
-------------------

Now process it with "ecpg input.pgc" which results in:
--- input.c ---
/* Processed by ecpg (4.0.1) */
/* These include files are added by the preprocessor */
#include <ecpgtype.h>
#include <ecpglib.h>
#include <ecpgerrno.h>
#include <sqlca.h>
/* End of automatic include section */
#line 1 "input.pgc"
int main()
{
  /* exec sql begin declare section */
#line 4 "input.pgc"
   struct varchar_v  { int len; char arr[ -1 ]; }  v   ;
/* exec sql end declare section */
#line 5 "input.pgc"
  return 0;
}
---------------

The array size of the struct is -1 and this does not compile:
input.pgc: In function `main':
input.pgc:4: error: size of array `arr' is negative

I suppose the size should have been 0 so it can be malloced by the backend.

pgsql-bugs by date:

Previous
From: Tom Lane
Date:
Subject: Re: BUG #1756: PQexec eats huge amounts of memory
Next
From: Kris Jurka
Date:
Subject: Re: BUG #1756: PQexec eats huge amounts of memory