Re: [Bug Fix]ECPG: cancellation of significant digits on ECPG

Tom Lane <tgl@sss.pgh.pa.us>

From: Tom Lane <tgl@sss.pgh.pa.us>
To: "Higuchi, Daisuke" <higuchi.daisuke@jp.fujitsu.com>
Cc: "'Dmitry Dolgov'" <9erthalion6@gmail.com>, PostgreSQL-development <pgsql-hackers@postgresql.org>
Date: 2018-11-12T23:07:20Z
Lists: pgsql-hackers

Attachments

"Higuchi, Daisuke" <higuchi.daisuke@jp.fujitsu.com> writes:
> From: Dmitry Dolgov [mailto:9erthalion6@gmail.com] 
>> Thanks for the patches. Unfortunately, judging from the cfbot.cputube.org they
>> can't be applied anymore to the current master, could you please rebase them?

> Thank you for checking!
> I rebased patches on the current master, so I attach them. 

I took a quick look at this.  I concur that the code is broken as-is;
it's failing to reproduce the state of the digit buffer accurately.
However, I think there's a second bug, which is that it doesn't even
try to duplicate the state when ndigits = 0.  That basically means that
the sqlda area might contain dangling pointers (they'll point to the
PGTYPESnumeric_from_asc output, which is freed immediately after we
set up the sqlda copy).  Now *maybe* that doesn't lead to any obvious
problem, but I don't think that this code deserves any expectation of
correctness given that you just found such a large bug in it.  So
I think that we ought to unconditionally make the sqlda value's digit
buffer look just like the one we're copying, even when ndigits = 0,
which just requires removing the tests on ndigits.

I also noted that the comment adjacent to this code was badly obsolete.

In short, the attached.  (I didn't bother to keep the test changes
separate from the code fix.)

			regards, tom lane

Commits

  1. Second try at fixing numeric data passed through an ECPG SQLDA.

  2. Fix incorrect results for numeric data passed through an ECPG SQLDA.