Re: [PATCH]Remove the redundant assignment

From: Michael Paquier <michael(at)paquier(dot)xyz>
To: Heikki Linnakangas <hlinnaka(at)iki(dot)fi>
Cc: Dagfinn Ilmari Mannsåker <ilmari(at)ilmari(dot)org>, 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-17 00:06:35
Message-ID: aUH0C433hc5R_htS@paquier.xyz
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Tue, Dec 16, 2025 at 04:02:53PM +0200, Heikki Linnakangas wrote:
>> 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';
>
> I don't know if these depend on the zero-padding...

Good question. This code has never been changed since its
introduction in a4f25b6a9c2d...

But anyway, looking more closely I think that we should be OK with
just switching to strlcpy() as long as we do the call with a "len + 1"
and not "len" to account for the zero termination based on the
allocations done just before copying the values.
--
Michael

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Michael Paquier 2025-12-17 00:08:02 Re: [PATCH]Remove the redundant assignment
Previous Message Peter Smith 2025-12-16 23:49:28 Re: [Proposal] Adding Log File Capability to pg_createsubscriber