aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/interfaces/ecpg/preproc/type.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/src/interfaces/ecpg/preproc/type.c b/src/interfaces/ecpg/preproc/type.c
index 7a81c349e02..5d9f83a4fd1 100644
--- a/src/interfaces/ecpg/preproc/type.c
+++ b/src/interfaces/ecpg/preproc/type.c
@@ -1,4 +1,4 @@
-/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/type.c,v 1.77.2.1 2008/03/02 10:57:21 meskes Exp $ */
+/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/type.c,v 1.77.2.2 2008/11/26 13:19:34 meskes Exp $ */
#include "postgres_fe.h"
@@ -327,8 +327,9 @@ ECPGdump_a_simple(FILE *o, const char *name, enum ECPGttype type,
fprintf(o, "\n\tECPGt_descriptor, %s, 0L, 0L, 0L, ", name);
else
{
- char *variable = (char *) mm_alloc(strlen(name) + ((prefix == NULL) ? 0 : strlen(prefix)) + 4);
- char *offset = (char *) mm_alloc(strlen(name) + strlen("sizeof(struct varchar_)") + 1 + strlen(varcharsize) + sizeof(int) * CHAR_BIT * 10 / 3);
+ char *variable = (char *) mm_alloc(strlen(name) + ((prefix == NULL) ? 0 : strlen(prefix)) + 4);
+ char *offset = (char *) mm_alloc(strlen(name) + strlen("sizeof(struct varchar_)") + 1 + strlen(varcharsize) + sizeof(int) * CHAR_BIT * 10 / 3);
+ char *var_name;
switch (type)
{
@@ -350,10 +351,14 @@ ECPGdump_a_simple(FILE *o, const char *name, enum ECPGttype type,
else
sprintf(variable, "&(%s%s)", prefix ? prefix : "", name);
+ /* remove trailing [] is name is array element */
+ var_name = strdup(name);
+ *(strchrnul(var_name, '[')) = '\0';
if (lineno)
- sprintf(offset, "sizeof(struct varchar_%s_%d)", name, lineno);
+ sprintf(offset, "sizeof(struct varchar_%s_%d)", var_name, lineno);
else
- sprintf(offset, "sizeof(struct varchar_%s)", name);
+ sprintf(offset, "sizeof(struct varchar_%s)", var_name);
+ free(var_name);
break;
case ECPGt_char:
case ECPGt_unsigned_char: