1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-18 17:42:25 +03:00

Fix handling of array of char pointers in ecpglib.

When array of char * was used as target for a FETCH statement returning more
than one row, it tried to store all the result in the first element. Instead it
should dump array of char pointers with right offset, use the address instead
of the value of the C variable while reading the array and treat such variable
as char **, instead of char * for pointer arithmetic.

Patch by Ashutosh Bapat <ashutosh.bapat@enterprisedb.com>
This commit is contained in:
Michael Meskes
2014-05-06 13:04:30 +02:00
parent 7d5b686218
commit 91c8c106fa
3 changed files with 31 additions and 3 deletions

View File

@ -455,6 +455,14 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno,
{
char *str = (char *) (var + offset * act_tuple);
/*
* If varcharsize is unknown and the offset is that of
* char *, then this variable represents the array of
* character pointers. So, use extra indirection.
*/
if (varcharsize == 0 && offset == sizeof(char *))
str = *(char **)str;
if (varcharsize == 0 || varcharsize > size)
{
strncpy(str, pval, size + 1);