Re: printing JsonbPair values of input JSONB on server side?

From: Andrew Gierth <andrew(at)tao11(dot)riddles(dot)org(dot)uk>
To: T L <tinlyx(at)gmail(dot)com>
Cc: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: printing JsonbPair values of input JSONB on server side?
Date: 2019-03-18 20:20:00
Message-ID: 87r2b4x7pg.fsf@news-spur.riddles.org.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

>>>>> "T" == T L <tinlyx(at)gmail(dot)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)

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message T L 2019-03-18 20:59:42 Re: printing JsonbPair values of input JSONB on server side?
Previous Message T L 2019-03-18 17:58:18 printing JsonbPair values of input JSONB on server side?