Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1b4uVk-00040l-QH for pgsql-hackers@arkaria.postgresql.org; Mon, 23 May 2016 18:23:28 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1b4uVk-0003au-Br for pgsql-hackers@arkaria.postgresql.org; Mon, 23 May 2016 18:23:28 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1b4uUP-00023Y-5R for pgsql-hackers@postgresql.org; Mon, 23 May 2016 18:22:05 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1b4uUL-0000su-Sy for pgsql-hackers@postgresql.org; Mon, 23 May 2016 18:22:04 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id u4NILxgq015228; Mon, 23 May 2016 14:21:59 -0400 From: Tom Lane To: David Rowley cc: Hao Lee , PostgreSQL-development Subject: Re: It's seems that the function "do_text_output_multiline" does not suit for format "line1\nline2\n...lineN". In-reply-to: References: Comments: In-reply-to David Rowley message dated "Sat, 21 May 2016 00:12:24 +1200" Date: Mon, 23 May 2016 14:21:59 -0400 Message-ID: <15227.1464027719@sss.pgh.pa.us> X-Pg-Spam-Score: -3.3 (---) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org David Rowley writes: > On 20 May 2016 at 19:13, Hao Lee 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. Agreed. > 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 -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers