From e8d1dcbfdeada534b1163d64770a65537c2dd177 Mon Sep 17 00:00:00 2001 From: Michael Meskes Date: Thu, 24 Aug 2006 10:35:58 +0000 Subject: [PATCH] Fixed of by one variable size. --- src/interfaces/ecpg/ChangeLog | 4 ++++ src/interfaces/ecpg/ecpglib/data.c | 22 +++++++++---------- src/interfaces/ecpg/preproc/preproc.y | 4 ++-- .../test/expected/compat_informix-rnull.c | 8 +++---- src/interfaces/ecpg/test/expected/sql-desc.c | 8 +++---- 5 files changed, 25 insertions(+), 21 deletions(-) diff --git a/src/interfaces/ecpg/ChangeLog b/src/interfaces/ecpg/ChangeLog index 165ba04f57..10dda45d76 100644 --- a/src/interfaces/ecpg/ChangeLog +++ b/src/interfaces/ecpg/ChangeLog @@ -2116,5 +2116,9 @@ We 23. Aug 09:32:14 CEST 2006 - Replaced double-quote-fix with a hopefully better version. - Use initializer string length as size for character strings. - Added ecpg_config.h file that is created via configure. + +Th 24. Aug 11:53:29 CEST 2006 + + - Fixed of by one variable size. - Set ecpg library version to 5.2. - Set ecpg version to 4.2.1. diff --git a/src/interfaces/ecpg/ecpglib/data.c b/src/interfaces/ecpg/ecpglib/data.c index 36d5449622..4f474d3bcf 100644 --- a/src/interfaces/ecpg/ecpglib/data.c +++ b/src/interfaces/ecpg/ecpglib/data.c @@ -1,4 +1,4 @@ -/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/data.c,v 1.33 2006/08/08 11:51:24 meskes Exp $ */ +/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/data.c,v 1.34 2006/08/24 10:35:58 meskes Exp $ */ #define POSTGRES_ECPG_INTERNAL #include "postgres_fe.h" @@ -406,33 +406,33 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno, case ECPGt_unsigned_char: if (pval) { - if (varcharsize == 0 || varcharsize > strlen(pval)) - strncpy((char *) ((long) var + offset * act_tuple), pval, strlen(pval) + 1); + if (varcharsize == 0 || varcharsize > size) + strncpy((char *) ((long) var + offset * act_tuple), pval, size + 1); else { strncpy((char *) ((long) var + offset * act_tuple), pval, varcharsize); - if (varcharsize < strlen(pval)) + if (varcharsize < size) { /* truncation */ switch (ind_type) { case ECPGt_short: case ECPGt_unsigned_short: - *((short *) (ind + ind_offset * act_tuple)) = strlen(pval); + *((short *) (ind + ind_offset * act_tuple)) = size; break; case ECPGt_int: case ECPGt_unsigned_int: - *((int *) (ind + ind_offset * act_tuple)) = strlen(pval); + *((int *) (ind + ind_offset * act_tuple)) = size; break; case ECPGt_long: case ECPGt_unsigned_long: - *((long *) (ind + ind_offset * act_tuple)) = strlen(pval); + *((long *) (ind + ind_offset * act_tuple)) = size; break; #ifdef HAVE_LONG_LONG_INT_64 case ECPGt_long_long: case ECPGt_unsigned_long_long: - *((long long int *) (ind + ind_offset * act_tuple)) = strlen(pval); + *((long long int *) (ind + ind_offset * act_tuple)) = size; break; #endif /* HAVE_LONG_LONG_INT_64 */ default: @@ -441,7 +441,7 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno, sqlca->sqlwarn[0] = sqlca->sqlwarn[1] = 'W'; } } - pval += strlen(pval); + pval += size; } break; @@ -451,7 +451,7 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno, struct ECPGgeneric_varchar *variable = (struct ECPGgeneric_varchar *) ((long) var + offset * act_tuple); - variable->len = strlen(pval); + variable->len = size; if (varcharsize == 0) strncpy(variable->arr, pval, variable->len); else @@ -489,7 +489,7 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno, variable->len = varcharsize; } } - pval += strlen(pval); + pval += size; } break; diff --git a/src/interfaces/ecpg/preproc/preproc.y b/src/interfaces/ecpg/preproc/preproc.y index da0631b6c6..d49d3795bc 100644 --- a/src/interfaces/ecpg/preproc/preproc.y +++ b/src/interfaces/ecpg/preproc/preproc.y @@ -1,4 +1,4 @@ -/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/preproc.y,v 1.330 2006/08/23 12:01:52 meskes Exp $ */ +/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/preproc.y,v 1.331 2006/08/24 10:35:58 meskes Exp $ */ /* Copyright comment */ %{ @@ -5422,7 +5422,7 @@ variable: opt_pointer ECPGColLabel opt_array_bounds opt_bit_field opt_initialize /* if we have an initializer but no string size set, let's use the initializer's length */ free(length); length = mm_alloc(i+sizeof("sizeof()")); - sprintf(length, "sizeof(%s)+1", $5+2); + sprintf(length, "sizeof(%s)", $5+2); } type = ECPGmake_simple_type(actual_type[struct_level].type_enum, length); } diff --git a/src/interfaces/ecpg/test/expected/compat_informix-rnull.c b/src/interfaces/ecpg/test/expected/compat_informix-rnull.c index fd6128a62e..74fcfc74a7 100644 --- a/src/interfaces/ecpg/test/expected/compat_informix-rnull.c +++ b/src/interfaces/ecpg/test/expected/compat_informix-rnull.c @@ -119,7 +119,7 @@ if (sqlca.sqlcode < 0) sqlprint ( );} { ECPGdo(__LINE__, 1, 0, NULL, "insert into test ( id , c , s , i , b , f , l , dbl ) values( 1 , ? , ? , ? , ? , ? , ? , ? ) ", - ECPGt_char,(c),(long)sizeof("abc ")+1,(long)1,(sizeof("abc ")+1)*sizeof(char), + ECPGt_char,(c),(long)sizeof("abc "),(long)1,(sizeof("abc "))*sizeof(char), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_short,&(s),(long)1,(long)1,sizeof(short), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, @@ -157,7 +157,7 @@ if (sqlca.sqlcode < 0) sqlprint ( );} rsetnull(CDTIMETYPE, (char *) &tmp); { ECPGdo(__LINE__, 1, 0, NULL, "insert into test ( id , c , s , i , b , f , l , dbl , dec , dat , tmp ) values( 2 , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? ) ", - ECPGt_char,(c),(long)sizeof("abc ")+1,(long)1,(sizeof("abc ")+1)*sizeof(char), + ECPGt_char,(c),(long)sizeof("abc "),(long)1,(sizeof("abc "))*sizeof(char), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_short,&(s),(long)1,(long)1,sizeof(short), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, @@ -192,7 +192,7 @@ if (sqlca.sqlcode < 0) sqlprint ( );} printf("first select\n"); { ECPGdo(__LINE__, 1, 0, NULL, "select c , s , i , b , f , l , dbl , dec , dat , tmp from test where id = 1 ", ECPGt_EOIT, - ECPGt_char,(c),(long)sizeof("abc ")+1,(long)1,(sizeof("abc ")+1)*sizeof(char), + ECPGt_char,(c),(long)sizeof("abc "),(long)1,(sizeof("abc "))*sizeof(char), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_short,&(s),(long)1,(long)1,sizeof(short), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, @@ -232,7 +232,7 @@ if (sqlca.sqlcode < 0) sqlprint ( );} printf("second select\n"); { ECPGdo(__LINE__, 1, 0, NULL, "select c , s , i , b , f , l , dbl , dec , dat , tmp from test where id = 2 ", ECPGt_EOIT, - ECPGt_char,(c),(long)sizeof("abc ")+1,(long)1,(sizeof("abc ")+1)*sizeof(char), + ECPGt_char,(c),(long)sizeof("abc "),(long)1,(sizeof("abc "))*sizeof(char), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_short,&(s),(long)1,(long)1,sizeof(short), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, diff --git a/src/interfaces/ecpg/test/expected/sql-desc.c b/src/interfaces/ecpg/test/expected/sql-desc.c index 2fc9eff1a6..2ca755b3a0 100644 --- a/src/interfaces/ecpg/test/expected/sql-desc.c +++ b/src/interfaces/ecpg/test/expected/sql-desc.c @@ -228,7 +228,7 @@ if (sqlca.sqlcode < 0) sqlprint();} { ECPGget_desc(__LINE__, "outdesc", 1,ECPGd_data, - ECPGt_char,(val2output),(long)sizeof("AAA")+1,(long)1,(sizeof("AAA")+1)*sizeof(char), ECPGd_EODT); + ECPGt_char,(val2output),(long)sizeof("AAA"),(long)1,(sizeof("AAA"))*sizeof(char), ECPGd_EODT); #line 51 "desc.pgc" @@ -254,7 +254,7 @@ if (sqlca.sqlcode < 0) sqlprint();} { ECPGdo(__LINE__, 0, 1, NULL, "fetch next from c1", ECPGt_EOIT, ECPGt_int,&(val1output),(long)1,(long)1,sizeof(int), ECPGt_int,&(ind1),(long)1,(long)1,sizeof(int), - ECPGt_char,(val2output),(long)sizeof("AAA")+1,(long)1,(sizeof("AAA")+1)*sizeof(char), + ECPGt_char,(val2output),(long)sizeof("AAA"),(long)1,(sizeof("AAA"))*sizeof(char), ECPGt_int,&(ind2),(long)1,(long)1,sizeof(int), ECPGt_EORT); #line 57 "desc.pgc" @@ -304,7 +304,7 @@ if (sqlca.sqlcode < 0) sqlprint();} { ECPGdo(__LINE__, 0, 1, NULL, "fetch next from c2", ECPGt_EOIT, ECPGt_int,&(val1output),(long)1,(long)1,sizeof(int), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, - ECPGt_char,(val2output),(long)sizeof("AAA")+1,(long)1,(sizeof("AAA")+1)*sizeof(char), + ECPGt_char,(val2output),(long)sizeof("AAA"),(long)1,(sizeof("AAA"))*sizeof(char), ECPGt_int,&(val2i),(long)1,(long)1,sizeof(int), ECPGt_EORT); #line 69 "desc.pgc" @@ -323,7 +323,7 @@ if (sqlca.sqlcode < 0) sqlprint();} { ECPGdo(__LINE__, 0, 1, NULL, "select * from test1 where a = 3 ", ECPGt_EOIT, ECPGt_int,&(val1output),(long)1,(long)1,sizeof(int), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, - ECPGt_char,(val2output),(long)sizeof("AAA")+1,(long)1,(sizeof("AAA")+1)*sizeof(char), + ECPGt_char,(val2output),(long)sizeof("AAA"),(long)1,(sizeof("AAA"))*sizeof(char), ECPGt_int,&(val2i),(long)1,(long)1,sizeof(int), ECPGt_EORT); #line 74 "desc.pgc"