Re: Convert Datum* to char*

From: Masterprojekt Naumann1 <mpws2013n1(at)gmail(dot)com>
To: Heikki Linnakangas <hlinnakangas(at)vmware(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Convert Datum* to char*
Date: 2014-01-06 13:46:15
Message-ID: CANjJybTSX1cqzxcbTNJ08rOXKanww_FbDP5==TPCrSze7F4vVQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Yes, in some cases, Datum is 0, which I test before conversion.
Additionally, I looked at tts_isnull but it does not prevent the
segmentation fault in some cases. The problem is. that sometimes the value
is random, but I don't know why and how I can detect that case.

2014/1/6 Heikki Linnakangas <hlinnakangas(at)vmware(dot)com>

> On 01/06/2014 03:09 PM, Masterprojekt Naumann1 wrote:
>
>> I want to read an attribute value from a TupleTableSlot. When I try to
>> convert an attribute of SQL type varchar from Datum* to char* with the
>> help
>> of the method TextDatumGetCString(...), sometimes there is a segmentation
>> fault. The segmentation fault comes from the method
>> TextDatumGetCString(...), which is defined in utils/builtins.h.
>> Unfortunately, the fault is not always reproducible. I debugged the code
>> and figured out that the value of result->tts_values[i] sometimes is
>> random. It may be uninitialized memory. In other cases, the variable value
>> is NULL. Then, I can just skip the conversion from Datum* to char*, so
>> that
>> there is no segmentation fault. I attached a patch with the code. The
>> relevant line is:
>> char *value = TextDatumGetCString(result->tts_values[i]);
>> The SQL-Query is a simple "SELECT * from ..." on the TPC-H table customer.
>> About every third execution leads to a segmentation fault.
>>
>
> Maybe the field is NULL? By convention, we normally set the Datum to 0 on
> an SQL NULL, but you're supposed to check tts_isnull first, and ignore
> tts_values[x] when tts_isnull[x] is true.
>
> - Heikki
>

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Andres Freund 2014-01-06 13:48:15 Re: Hot standby 9.2.6 -> 9.2.6 PANIC: WAL contains references to invalid pages
Previous Message Heikki Linnakangas 2014-01-06 13:18:41 Re: Convert Datum* to char*