Fix jsonb_from_cstring parameter type for length

From: Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>
To: Postgres hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Fix jsonb_from_cstring parameter type for length
Date: 2025-09-19 06:45:22
Message-ID: CAEoWx2n-OWFAWhbVXHiBqHxTOKz71LCoX6EtuJ=z=5pkHFe-Ag@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi Hackers,

While reading the code of jsonb_from_ctring(char *json, int len, bool ...),
I found that:

1. len should be type of size_t. Because len is only used when calling
makeJsonLexContextCstring(&lex, json, len, ...),
where makeJsonLexContextCstring() is defined with size_t for len.
jsonb_from_cstring() is a local static function, it is called 3 times, 2 of
callers pass size_t len to it, and only one caller passes int len to it.

2. The first parameter "json" can be a const string, as this function
passes "json" to makeJsonLexContextCstring() and it defines "json" as
const char *.

So I corrected the function interface. Build passed without warning and
"make check" passed as well.

Best regards,
Chao Li (Evan)
---------------------
HighGo Software Co., Ltd.
https://www.highgo.com/

Attachment Content-Type Size
v1-0001-Make-jsonb_from_cstring-parameters-more-accurate-.patch application/octet-stream 1.5 KB

Browse pgsql-hackers by date

  From Date Subject
Next Message Chao Li 2025-09-19 06:56:27 Re: encode/decode support for base64url
Previous Message Florents Tselai 2025-09-19 06:45:21 Re: encode/decode support for base64url