Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WSB2w-0002EO-NC for pgsql-bugs@arkaria.postgresql.org; Mon, 24 Mar 2014 20:00:34 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1WSB2w-0003e2-7R for pgsql-bugs@arkaria.postgresql.org; Mon, 24 Mar 2014 20:00:34 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WSB2v-0003dw-FP for pgsql-bugs@postgresql.org; Mon, 24 Mar 2014 20:00:33 +0000 Received: from momjian.us ([72.94.173.45]) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WSB2s-0004Hh-1W; Mon, 24 Mar 2014 20:00:32 +0000 Received: from bruce by momjian.us with local (Exim 4.72) (envelope-from ) id 1WSB2q-00023X-K0; Mon, 24 Mar 2014 16:00:28 -0400 Date: Mon, 24 Mar 2014 16:00:28 -0400 From: Bruce Momjian To: Tom Lane Cc: Tatsuo Ishii , pg@heroku.com, pgsql-bugs@postgresql.org Subject: Re: PQclientEncoding() returns -1, resulting in possible assertion failure in psql Message-ID: <20140324200028.GF15836@momjian.us> References: <14465.1386526658@sss.pgh.pa.us> <15210.1386529004@sss.pgh.pa.us> <20131209.081735.1321847791044178990.t-ishii@sraoss.co.jp> <20140322015325.GA21843@momjian.us> <20140322151723.GB21843@momjian.us> <19770.1395503756@sss.pgh.pa.us> <20140323001711.GA5606@momjian.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20140323001711.GA5606@momjian.us> User-Agent: Mutt/1.5.20 (2009-06-14) X-Pg-Spam-Score: -2.4 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org On Sat, Mar 22, 2014 at 08:17:11PM -0400, Bruce Momjian wrote: > On Sat, Mar 22, 2014 at 11:55:56AM -0400, Tom Lane wrote: > > Bruce Momjian writes: > > > OK, hearing nothing, I dug into this, and I think the solution is > > > simpler than we thought. Basically, the Assert is checking for the > > > encoding value to be in a valid range, but the main code is also > > > checking for an invalid encoding and returning PG_SQL_ASCII: > > > > Agreed that that's pretty useless. I wonder though why these functions > > are not coded like > > > > return PG_VALID_ENCODING(encoding) ? > > ((*pg_wchar_table[encoding].mblen) ((const unsigned char *) mbstr)) : > > ((*pg_wchar_table[PG_SQL_ASCII].mblen) ((const unsigned char *) mbstr))); > > > > instead of the hard-to-read explicit range check. > > Agreed. Modified patch attached. Patch applied. I did not backpatch because it only affects assert builds, which I assume is only being done in head. -- Bruce Momjian http://momjian.us EnterpriseDB http://enterprisedb.com + Everyone has their own god. + -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs