Re: [PATCH]Remove the redundant assignment

Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>

From: Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>
To: Michael Paquier <michael@paquier.xyz>
Cc: Chao Li <li.evan.chao@gmail.com>, Feilong Meng <feelingmeng@foxmail.com>, pgsql-hackers <pgsql-hackers@lists.postgresql.org>
Date: 2025-12-16T11:16:47Z
Lists: pgsql-hackers

Commits

Same data as JSON: GET /api/v1/messages/:b64id/commits the thread's linked commits as JSON, with link sources. API reference →
  1. Remove useless code in InjectionPointAttach()

Michael Paquier <michael@paquier.xyz> writes:

> On Tue, Dec 16, 2025 at 03:08:25PM +0800, Chao Li wrote:
>> Given that, I agree we should remove the redundant assignments to
>> keep the code clearer and consistent. 
>
> Yeah, these could be removed.  I am wondering why 0eb23285a257 did not
> bother, but that's no big deal one way or another, just less code at
> the end of the day.

A quick grep reveals a bunch of strncpy() calls followed by a '\0'
assignment that could be replaced with strlcpy():

$ rg -A1 strncpy|rg -B1 "= '\\\\0';"
src/interfaces/libpq/fe-secure-openssl.c:		strncpy(buf, conn->sslpassword, size);
src/interfaces/libpq/fe-secure-openssl.c-		buf[size - 1] = '\0';
--
src/bin/pgbench/pgbench.c:		strncpy(*script, option, namelen);
src/bin/pgbench/pgbench.c-		(*script)[namelen] = '\0';
--
doc/src/sgml/ecpg.sgml:            strncpy(name_buf, v.sqlname.data, v.sqlname.length);
doc/src/sgml/ecpg.sgml-            name_buf[v.sqlname.length] = '\0';
--
doc/src/sgml/ecpg.sgml:                strncpy(name_buf, v.sqlname.data, v.sqlname.length);
doc/src/sgml/ecpg.sgml-                name_buf[v.sqlname.length] = '\0';
--
src/interfaces/ecpg/ecpglib/execute.c:					strncpy(newcopy, (char *) var->value, slen);
src/interfaces/ecpg/ecpglib/execute.c-					newcopy[slen] = '\0';
--
src/interfaces/ecpg/ecpglib/execute.c:					strncpy(mallocedval, (char *) var->value, slen);
src/interfaces/ecpg/ecpglib/execute.c-					mallocedval[slen] = '\0';
--
src/interfaces/ecpg/ecpglib/execute.c:					strncpy(newcopy, variable->arr, variable->len);
src/interfaces/ecpg/ecpglib/execute.c-					newcopy[variable->len] = '\0';
--
src/backend/utils/adt/name.c:	strncpy(NameStr(*name), str, NAMEDATALEN);
src/backend/utils/adt/name.c-	NameStr(*name)[NAMEDATALEN - 1] = '\0';

- ilmari