Fixed of by one variable size.

This commit is contained in:
Michael Meskes 2006-08-24 10:35:58 +00:00
parent b7d5a88dbb
commit e8d1dcbfde
5 changed files with 25 additions and 21 deletions

View File

@ -2116,5 +2116,9 @@ We 23. Aug 09:32:14 CEST 2006
- Replaced double-quote-fix with a hopefully better version. - Replaced double-quote-fix with a hopefully better version.
- Use initializer string length as size for character strings. - Use initializer string length as size for character strings.
- Added ecpg_config.h file that is created via configure. - 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 library version to 5.2.
- Set ecpg version to 4.2.1. - Set ecpg version to 4.2.1.

View File

@ -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 #define POSTGRES_ECPG_INTERNAL
#include "postgres_fe.h" #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: case ECPGt_unsigned_char:
if (pval) if (pval)
{ {
if (varcharsize == 0 || varcharsize > strlen(pval)) if (varcharsize == 0 || varcharsize > size)
strncpy((char *) ((long) var + offset * act_tuple), pval, strlen(pval) + 1); strncpy((char *) ((long) var + offset * act_tuple), pval, size + 1);
else else
{ {
strncpy((char *) ((long) var + offset * act_tuple), pval, varcharsize); strncpy((char *) ((long) var + offset * act_tuple), pval, varcharsize);
if (varcharsize < strlen(pval)) if (varcharsize < size)
{ {
/* truncation */ /* truncation */
switch (ind_type) switch (ind_type)
{ {
case ECPGt_short: case ECPGt_short:
case ECPGt_unsigned_short: case ECPGt_unsigned_short:
*((short *) (ind + ind_offset * act_tuple)) = strlen(pval); *((short *) (ind + ind_offset * act_tuple)) = size;
break; break;
case ECPGt_int: case ECPGt_int:
case ECPGt_unsigned_int: case ECPGt_unsigned_int:
*((int *) (ind + ind_offset * act_tuple)) = strlen(pval); *((int *) (ind + ind_offset * act_tuple)) = size;
break; break;
case ECPGt_long: case ECPGt_long:
case ECPGt_unsigned_long: case ECPGt_unsigned_long:
*((long *) (ind + ind_offset * act_tuple)) = strlen(pval); *((long *) (ind + ind_offset * act_tuple)) = size;
break; break;
#ifdef HAVE_LONG_LONG_INT_64 #ifdef HAVE_LONG_LONG_INT_64
case ECPGt_long_long: case ECPGt_long_long:
case ECPGt_unsigned_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; break;
#endif /* HAVE_LONG_LONG_INT_64 */ #endif /* HAVE_LONG_LONG_INT_64 */
default: 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'; sqlca->sqlwarn[0] = sqlca->sqlwarn[1] = 'W';
} }
} }
pval += strlen(pval); pval += size;
} }
break; 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 *variable =
(struct ECPGgeneric_varchar *) ((long) var + offset * act_tuple); (struct ECPGgeneric_varchar *) ((long) var + offset * act_tuple);
variable->len = strlen(pval); variable->len = size;
if (varcharsize == 0) if (varcharsize == 0)
strncpy(variable->arr, pval, variable->len); strncpy(variable->arr, pval, variable->len);
else else
@ -489,7 +489,7 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
variable->len = varcharsize; variable->len = varcharsize;
} }
} }
pval += strlen(pval); pval += size;
} }
break; break;

View File

@ -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 */ /* 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 */ /* if we have an initializer but no string size set, let's use the initializer's length */
free(length); free(length);
length = mm_alloc(i+sizeof("sizeof()")); 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); type = ECPGmake_simple_type(actual_type[struct_level].type_enum, length);
} }

View File

@ -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 , ? , ? , ? , ? , ? , ? , ? ) ", { 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_NO_INDICATOR, NULL , 0L, 0L, 0L,
ECPGt_short,&(s),(long)1,(long)1,sizeof(short), ECPGt_short,&(s),(long)1,(long)1,sizeof(short),
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
@ -157,7 +157,7 @@ if (sqlca.sqlcode < 0) sqlprint ( );}
rsetnull(CDTIMETYPE, (char *) &tmp); 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 , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? ) ", { 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_NO_INDICATOR, NULL , 0L, 0L, 0L,
ECPGt_short,&(s),(long)1,(long)1,sizeof(short), ECPGt_short,&(s),(long)1,(long)1,sizeof(short),
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
@ -192,7 +192,7 @@ if (sqlca.sqlcode < 0) sqlprint ( );}
printf("first select\n"); 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, { 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_NO_INDICATOR, NULL , 0L, 0L, 0L,
ECPGt_short,&(s),(long)1,(long)1,sizeof(short), ECPGt_short,&(s),(long)1,(long)1,sizeof(short),
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
@ -232,7 +232,7 @@ if (sqlca.sqlcode < 0) sqlprint ( );}
printf("second select\n"); 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, { 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_NO_INDICATOR, NULL , 0L, 0L, 0L,
ECPGt_short,&(s),(long)1,(long)1,sizeof(short), ECPGt_short,&(s),(long)1,(long)1,sizeof(short),
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,

View File

@ -228,7 +228,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
{ ECPGget_desc(__LINE__, "outdesc", 1,ECPGd_data, { 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" #line 51 "desc.pgc"
@ -254,7 +254,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
{ ECPGdo(__LINE__, 0, 1, NULL, "fetch next from c1", ECPGt_EOIT, { ECPGdo(__LINE__, 0, 1, NULL, "fetch next from c1", ECPGt_EOIT,
ECPGt_int,&(val1output),(long)1,(long)1,sizeof(int), ECPGt_int,&(val1output),(long)1,(long)1,sizeof(int),
ECPGt_int,&(ind1),(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); ECPGt_int,&(ind2),(long)1,(long)1,sizeof(int), ECPGt_EORT);
#line 57 "desc.pgc" #line 57 "desc.pgc"
@ -304,7 +304,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
{ ECPGdo(__LINE__, 0, 1, NULL, "fetch next from c2", ECPGt_EOIT, { ECPGdo(__LINE__, 0, 1, NULL, "fetch next from c2", ECPGt_EOIT,
ECPGt_int,&(val1output),(long)1,(long)1,sizeof(int), ECPGt_int,&(val1output),(long)1,(long)1,sizeof(int),
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 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); ECPGt_int,&(val2i),(long)1,(long)1,sizeof(int), ECPGt_EORT);
#line 69 "desc.pgc" #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, { ECPGdo(__LINE__, 0, 1, NULL, "select * from test1 where a = 3 ", ECPGt_EOIT,
ECPGt_int,&(val1output),(long)1,(long)1,sizeof(int), ECPGt_int,&(val1output),(long)1,(long)1,sizeof(int),
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 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); ECPGt_int,&(val2i),(long)1,(long)1,sizeof(int), ECPGt_EORT);
#line 74 "desc.pgc" #line 74 "desc.pgc"