Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h5yjw-00040C-RL for pgsql-general@arkaria.postgresql.org; Mon, 18 Mar 2019 20:20:08 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1h5yjv-0005dL-MO for pgsql-general@arkaria.postgresql.org; Mon, 18 Mar 2019 20:20:07 +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_SHA1:256) (Exim 4.89) (envelope-from ) id 1h5yjv-0005dE-E1 for pgsql-general@lists.postgresql.org; Mon, 18 Mar 2019 20:20:07 +0000 Received: from lungold.riddles.org.uk ([82.68.208.19]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h5yjs-0006hw-4T for pgsql-general@lists.postgresql.org; Mon, 18 Mar 2019 20:20:06 +0000 Received: from [192.168.127.1] (port=11710 helo=caithnard.riddles.org.uk) by lungold.riddles.org.uk with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.88 (FreeBSD)) (envelope-from ) id 1h5yjp-000Nxv-Lf; Mon, 18 Mar 2019 20:20:01 +0000 Received: from [127.0.0.1] (port=47407 helo=caithnard.riddles.org.uk) by caithnard.riddles.org.uk with esmtp (Exim 4.89 (FreeBSD)) (envelope-from ) id 1h5yjo-0000zl-VT; Mon, 18 Mar 2019 20:20:01 +0000 From: Andrew Gierth To: T L Cc: pgsql-general@lists.postgresql.org Subject: Re: printing JsonbPair values of input JSONB on server side? In-Reply-To: (T. L.'s message of "Mon, 18 Mar 2019 12:58:18 -0500") Message-ID: <87r2b4x7pg.fsf@news-spur.riddles.org.uk> References: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (berkeley-unix) Date: Mon, 18 Mar 2019 20:20:00 +0000 MIME-Version: 1.0 Content-Type: text/plain List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk >>>>> "T" == T L writes: T> //Problem line!!! T> // elog(NOTICE, "print_kv_pair(): k = %s, v = %s", T> ptr-> key.val.string.val, numeric_out(ptr->value.val.numeric)); string.val isn't a C string (notice the "not null terminated" comment in the structure definition), and you can't call numeric_out like that. Either of those would crash it. You could use pnstrdup to get a valid C string, and use DatumGetCString(DirectFunctionCall1( numeric_out, NumericGetDatum(ptr->value.val.numeric))) to get the numeric value as a C string. -- Andrew (irc:RhodiumToad)