From: Andrew Gierth <andrew@tao11.riddles.org.uk>
To: T L <tinlyx@gmail.com>
Cc: pgsql-general@lists.postgresql.org
Subject: Re: printing JsonbPair values of input JSONB on server side?
Date: Mon, 18 Mar 2019 20:20:00 +0000
Message-ID: <87r2b4x7pg.fsf@news-spur.riddles.org.uk> (raw)
In-Reply-To: <CAOb=C0c=iuYXAL-b-19t-F0XcPBQOin+vReOqSa2BYminvg6Zw@mail.gmail.com>
References: <CAOb=C0c=iuYXAL-b-19t-F0XcPBQOin+vReOqSa2BYminvg6Zw@mail.gmail.com>
>>>>> "T" == T L <tinlyx@gmail.com> 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)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: andrew@tao11.riddles.org.uk, tinlyx@gmail.com
Subject: Re: printing JsonbPair values of input JSONB on server side?
In-Reply-To: <87r2b4x7pg.fsf@news-spur.riddles.org.uk>
References: <CAOb=C0c=iuYXAL-b-19t-F0XcPBQOin+vReOqSa2BYminvg6Zw@mail.gmail.com> <87r2b4x7pg.fsf@news-spur.riddles.org.uk>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox