[PATCH] clarify palloc comment on quote_literal_cstr

Steve Chavez <steve@supabase.io>

From: Steve Chavez <steve@supabase.io>
To: PostgreSQL-development <pgsql-hackers@postgresql.org>
Date: 2025-04-06T17:37:24Z
Lists: pgsql-hackers

Attachments

Hello hackers,

I found the numbers in `quote_literal_cstr` palloc quite magical. So I've
added a comment clarifying what they mean. The change is small:

        /* We make a worst-case result area; wasting a little space is OK */
-       result = palloc(len * 2 + 3 + 1);
+       result = palloc(
+               (len * 2)    /* worst-case doubling for every character if
each one is a quote */
+               + 3          /* two outer quotes + possibly 'E' if needed */
+               + 1          /* null terminator */
+       );

Best regards,
Steve

Commits

Same data as JSON: GET /api/v1/messages/:b64id/commits the thread's linked commits as JSON, with link sources. API reference →
  1. Clarify comment for worst-case allocation in quote_literal_cstr()