| From: | Dagfinn Ilmari Mannsåker <ilmari(at)ilmari(dot)org> |
|---|---|
| To: | Michael Paquier <michael(at)paquier(dot)xyz> |
| Cc: | Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>, Feilong Meng <feelingmeng(at)foxmail(dot)com>, pgsql-hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org> |
| Subject: | Re: [PATCH]Remove the redundant assignment |
| Date: | 2025-12-16 11:16:47 |
| Message-ID: | 87ecou65i8.fsf@wibble.ilmari.org |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Michael Paquier <michael(at)paquier(dot)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
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Hayato Kuroda (Fujitsu) | 2025-12-16 11:35:34 | RE: Parallel Apply |
| Previous Message | cca5507 | 2025-12-16 11:16:20 | A small problem when rehashing catalog cache |