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.