Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit91c8c10

Browse files
author
Michael Meskes
committed
Fix handling of array of char pointers in ecpglib.
When array of char * was used as target for a FETCH statement returning morethan one row, it tried to store all the result in the first element. Instead itshould dump array of char pointers with right offset, use the address insteadof the value of the C variable while reading the array and treat such variableas char **, instead of char * for pointer arithmetic.Patch by Ashutosh Bapat <ashutosh.bapat@enterprisedb.com>
1 parent7d5b686 commit91c8c10

File tree

3 files changed

+31
-3
lines changed

3 files changed

+31
-3
lines changed

‎src/interfaces/ecpg/ecpglib/data.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,14 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno,
455455
{
456456
char*str= (char*) (var+offset*act_tuple);
457457

458+
/*
459+
* If varcharsize is unknown and the offset is that of
460+
* char *, then this variable represents the array of
461+
* character pointers. So, use extra indirection.
462+
*/
463+
if (varcharsize==0&&offset==sizeof(char*))
464+
str=*(char**)str;
465+
458466
if (varcharsize==0||varcharsize>size)
459467
{
460468
strncpy(str,pval,size+1);

‎src/interfaces/ecpg/ecpglib/execute.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1851,7 +1851,14 @@ ECPGdo(const int lineno, const int compat, const int force_indicator, const char
18511851
var->arrsize=va_arg(args,long);
18521852
var->offset=va_arg(args,long);
18531853

1854-
if (var->arrsize==0||var->varcharsize==0)
1854+
/*
1855+
* Unknown array size means pointer to an array.
1856+
* Unknown varcharsize usually also means pointer. But if the
1857+
* type is character and the array size is known, it is an
1858+
* array of pointers to char, so use var->pointer as it is.
1859+
*/
1860+
if (var->arrsize==0||
1861+
(var->varcharsize==0&& ((var->type!=ECPGt_char&&var->type!=ECPGt_unsigned_char)|| (var->arrsize <=1))))
18551862
var->value=*((char**) (var->pointer));
18561863
else
18571864
var->value=var->pointer;

‎src/interfaces/ecpg/preproc/type.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,8 @@ ECPGdump_a_simple(FILE *o, const char *name, enum ECPGttype type,
407407
caseECPGt_unsigned_char:
408408
caseECPGt_char_variable:
409409
caseECPGt_string:
410-
410+
{
411+
char*sizeof_name="char";
411412
/*
412413
* we have to use the pointer except for arrays with given
413414
* bounds, ecpglib will distinguish between * and []
@@ -417,12 +418,24 @@ ECPGdump_a_simple(FILE *o, const char *name, enum ECPGttype type,
417418
(atoi(varcharsize)==0&&strcmp(varcharsize,"0")!=0)||
418419
(atoi(arrsize)==0&&strcmp(arrsize,"0")!=0))
419420
&&siz==NULL)
421+
{
420422
sprintf(variable,"(%s%s)",prefix ?prefix :"",name);
423+
if ((type==ECPGt_char||type==ECPGt_unsigned_char)&&
424+
strcmp(varcharsize,"0")==0)
425+
{
426+
/*
427+
* If this is an array of char *, the offset would be
428+
* sizeof(char *) and not sizeof(char).
429+
*/
430+
sizeof_name="char *";
431+
}
432+
}
421433
else
422434
sprintf(variable,"&(%s%s)",prefix ?prefix :"",name);
423435

424-
sprintf(offset,"(%s)*sizeof(char)",strcmp(varcharsize,"0")==0 ?"1" :varcharsize);
436+
sprintf(offset,"(%s)*sizeof(%s)",strcmp(varcharsize,"0")==0 ?"1" :varcharsize,sizeof_name);
425437
break;
438+
}
426439
caseECPGt_numeric:
427440

428441
/*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp