Remove post-increment in function quote_identifier of pg_upgrade

From: Vaibhav Dalvi <vaibhav(dot)dalvi(at)enterprisedb(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Remove post-increment in function quote_identifier of pg_upgrade
Date: 2021-04-29 13:05:28
Message-ID: CA+vB=AHVLrO=Pgr-ZyJ_31+bK1pug5oapU0VbqTckpqLYEcd+g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

The function quote_identifier has extra post-increment operation as
highlighted below,

char *
quote_identifier(const char *s)
{
char *result = pg_malloc(strlen(s) * 2 + 3);
char *r = result;

*r++ = '"';
while (*s)
{
if (*s == '"')
*r++ = *s;
*r++ = *s;
s++;
}
*r++ = '"';
**r++ = '\0';*

return result;
}

I think *r = '\0' is enough here. Per precedence table the precedence of
postfix increment operator is higher. The above statement increments 'r'
pointer address but returns the original un-incremented pointer address,
which is then dereferenced. Correct me if I am wrong here.

If my understanding is correct then '++' is not needed in the
above highlighted statement which is leading to overhead.

Find an attached patch which does the same. This can be backported till v96.

Thanks & Regards,
Vaibhav Dalvi
[image: image.png]

Attachment Content-Type Size
remove_extra_postincrement_in_quote_identifier_pg_upgrade.patch text/x-patch 289 bytes

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Alvaro Herrera 2021-04-29 13:55:43 Re: Unresolved repliaction hang and stop problem.
Previous Message vignesh C 2021-04-29 12:44:06 Re: Replication slot stats misgivings