Re: It's seems that the function "do_text_output_multiline" does not suit for format "line1\nline2\n...lineN".

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: David Rowley <david(dot)rowley(at)2ndquadrant(dot)com>
Cc: Hao Lee <mixtrue(at)gmail(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: It's seems that the function "do_text_output_multiline" does not suit for format "line1\nline2\n...lineN".
Date: 2016-05-23 18:21:59
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

David Rowley <david(dot)rowley(at)2ndquadrant(dot)com> writes:
> On 20 May 2016 at 19:13, Hao Lee <mixtrue(at)gmail(dot)com> wrote:
>> Today, I am do some works on adding some customized featues to PostgreSQL 9.6 beta1. But, when i do some output to psql using the fuction "do_text_output_multiline" with the string just like mentioned in mail tilte, such as "this is a\ntest for\nnew blank.". the PostgreSQL may lead to corruption in this function, and i debugged it that found this function can not dealt with the boundaries properly. The original function code as :

> Thanks for reporting this. It does seem pretty broken. I guess we've
> only gotten away with this due to EXPLAIN output lines always having a
> \n at the end of them, but we should fix this.


> Your proposed fix looks a little bit confused. You could have just
> removed the eol += len; as testing if (eol) in the else will never be
> true as that else is only being hit because eol is NULL.

I think really the right fix is "eol = text + len" rather than modifying
the loop condition. Almost certainly, that is what the original coder
intended, but typo'd the statement and nobody ever noticed.

> I shuffled things around in there a bit and came up with the attached fix.

I didn't like this version because it duplicated the string-conversion
code, which admittedly is only one line, but not a very simple line.
I pushed something based on "eol = text + len" instead.

regards, tom lane

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2016-05-23 18:27:23 Re: Changed SRF in targetlist handling
Previous Message Marko Tiikkaja 2016-05-23 17:47:36 Re: Calling json_* functions with JSONB data