Greetings,
I'm having a problem using heap_form_tuple. I'm trying to form a HeapTuple to 
use it later with simple_heap_insert. My code looks like this:

------------------

Datum *values;
bool *nulls;
int natts;
TupleDesc tupDesc;
HeapTuple tuple;
...
tupDesc = RelationGetDescr(...my previously opened relation...);
natts = tupDesc->natts;

values = (Datum *)palloc(natts*sizeof(Datum *));
nulls = (bool *)palloc(natts*sizeof(bool *));

memset(nulls, false, natts * sizeof(nulls));

values[0] = ...GetDatum(...my datum...);
...
values[natts-1] = ...GetDatum(...my datum...);
...
tuple = heap_form_tuple(tupDesc, values, nulls);

------------------

When I come to last line, I get these errors (I'm using valgrind):

==25850== Source and destination overlap in memcpy(0x8BCB070, 0x4CF2480, 
496753820)
==25850==    at 0x4024586: memcpy (in 
/usr/lib/valgrind/x86-linux/vgpreload_memcheck.so)
==25850==    by 0x808C811: heap_fill_tuple (in /usr/local/pgsql/bin/postgres)
==25850==    by 0x808D72F: heap_form_tuple (in /usr/local/pgsql/bin/postgres)
...
==25850== Invalid read of size 1
==25850==    at 0x40245A1: memcpy (in 
/usr/lib/valgrind/x86-linux/vgpreload_memcheck.so)
==25850==    by 0x808C811: heap_fill_tuple (in /usr/local/pgsql/bin/postgres)
==25850==    by 0x808D72F: heap_form_tuple (in /usr/local/pgsql/bin/postgres)
...
==25850==  Address 0x8BCB027 is 1 bytes before a block of size 496,753,892 
alloc'd
==25850==    at 0x4022825: malloc (in 
/usr/lib/valgrind/x86-linux/vgpreload_memcheck.so)
==25850==    by 0x82BE278: AllocSetAlloc (in /usr/local/pgsql/bin/postgres)
==25850==    by 0x82BEE91: MemoryContextAllocZero (in 
/usr/local/pgsql/bin/postgres)
==25850==    by 0x808D694: heap_form_tuple (in /usr/local/pgsql/bin/postgres)
...
==25850==  Address 0x8BCB027 is 2 bytes before a block of size 496,753,892 
alloc'd
...
==25850==  Address 0x8BCB027 is 3 bytes before a block of size 496,753,892 
alloc'd
...
==25850==  Address 0x8BCB027 is 4 bytes before a block of size 496,753,892 
alloc'd
...
==25850== Process terminating with default action of signal 11 (SIGSEGV)
==25850==  Access not within mapped region at address 0x8BCAFFF
==25850==    at 0x40245A1: memcpy (in 
/usr/lib/valgrind/x86-linux/vgpreload_memcheck.so)
==25850==    by 0x808C811: heap_fill_tuple (in /usr/local/pgsql/bin/postgres)
==25850==    by 0x808D72F: heap_form_tuple (in /usr/local/pgsql/bin/postgres)

If I work on tables with only 1 attribute, I use normal variables (Datum 
values, bool nulls) instead of arrays, and using heap_form_tuple(TupleDesc td, 
&values, &nulls) works flawlessly. What am i missing?

Thanks in advance for help,
Claudio Rossi



-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to