Re: Convert Datum* to char*
От | Masterprojekt Naumann1 |
---|---|
Тема | Re: Convert Datum* to char* |
Дата | |
Msg-id | CANjJybTSX1cqzxcbTNJ08rOXKanww_FbDP5==TPCrSze7F4vVQ@mail.gmail.com обсуждение исходный текст |
Ответ на | Re: Convert Datum* to char* (Heikki Linnakangas <hlinnakangas@vmware.com>) |
Список | pgsql-hackers |
<div dir="ltr">Yes, in some cases, Datum is 0, which I test before conversion. Additionally, I looked at tts_isnull but itdoes not prevent the segmentation fault in some cases. The problem is. that sometimes the value is random, but I don'tknow why and how I can detect that case.<br /></div><div class="gmail_extra"><br /><br /><div class="gmail_quote">2014/1/6Heikki Linnakangas <span dir="ltr"><<a href="mailto:hlinnakangas@vmware.com" target="_blank">hlinnakangas@vmware.com</a>></span><br/><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px#ccc solid;padding-left:1ex"><div class="im">On 01/06/2014 03:09 PM, Masterprojekt Naumann1 wrote:<br/><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"> I wantto read an attribute value from a TupleTableSlot. When I try to<br /> convert an attribute of SQL type varchar from Datum*to char* with the help<br /> of the method TextDatumGetCString(...), sometimes there is a segmentation<br /> fault.The segmentation fault comes from the method<br /> TextDatumGetCString(...), which is defined in utils/builtins.h.<br/> Unfortunately, the fault is not always reproducible. I debugged the code<br /> and figured out thatthe value of result->tts_values[i] sometimes is<br /> random. It may be uninitialized memory. In other cases, thevariable value<br /> is NULL. Then, I can just skip the conversion from Datum* to char*, so that<br /> there is no segmentationfault. I attached a patch with the code. The<br /> relevant line is:<br /> char *value = TextDatumGetCString(result-><u></u>tts_values[i]);<br/> The SQL-Query is a simple "SELECT * from ..." on the TPC-H tablecustomer.<br /> About every third execution leads to a segmentation fault.<br /></blockquote><br /></div> Maybe thefield 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.<span class="HOEnZb"><font color="#888888"><br /><br /> - Heikki<br/></font></span></blockquote></div><br /></div>
В списке pgsql-hackers по дате отправления: