Search Postgresql Archives

Re: C function returns null values

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Thanks for your answer. I edited my code, but still get these random null values. What else can I do ?

Regards

-----Ursprüngliche Nachricht-----
Von: Tom Lane [mailto:tgl@xxxxxxxxxxxxx] 
Gesendet: Freitag, 15. Juli 2011 16:24
An: Gregor Trefs
Cc: pgsql-general@xxxxxxxxxxxxxx
Betreff: Re:  C function returns null values 

Gregor Trefs <gregor.trefs@xxxxxxxxxxx> writes:
> I developed a C function which returns a record. The record contains 3 scalar values and 2 arrays. Randomly some record elements are null and I wonder why. I could trace down the problem to the point where the return record is created. Until this point everything is computed correctly. Below you see an excerpt of the relevant code. I use PostGres 8.4 on Ubuntu 10.10 (x64).

You're not bothering to fill in the nulls[] array:

>     // Allocate enough memory for nulls
>     nulls = palloc(tuplen * sizeof (bool));
>     // Create tuple
>     res_tuple = heap_form_tuple(tupdesc, values, nulls);

palloc0 would work better here.

BTW, it's a good idea to develop/test C code in a backend built with --enable-debug --enable-cassert.  Had you been doing so, palloc would have given you back intentionally-garbage-filled memory, and you'd have noticed the mistake immediately.

			regards, tom lane

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



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux