Re: pgsql: Add missing string terminator

2025-04-30 Thread Daniel Gustafsson
> On 30 Apr 2025, at 15:14, David Rowley wrote: > On Thu, 1 May 2025 at 00:44, Peter Eisentraut wrote: >> I think it's best in general to use str* for strings and mem* for >> not-strings. That's easier to read and also better for static analyzers >> etc. > > The reason I think memcpy is better

Re: pgsql: Add missing string terminator

2025-04-30 Thread David Rowley
On Thu, 1 May 2025 at 00:44, Peter Eisentraut wrote: > > On 30.04.25 13:56, David Rowley wrote: > > In case you're looking for inspiration on a standard to follow, > > commits such as 586dd5d6a did seem to favour memcpy() when the length > > was known and only use strlcpy() when it wasn't. > > It

Re: pgsql: Add missing string terminator

2025-04-30 Thread Peter Eisentraut
On 30.04.25 13:56, David Rowley wrote: On Wed, 30 Apr 2025 at 23:43, David Rowley wrote: memcpy() would make more sense IMO, since the length is known already. I'm fine with either, however. In case you're looking for inspiration on a standard to follow, commits such as 586dd5d6a did seem to

Re: pgsql: Add missing string terminator

2025-04-30 Thread David Rowley
On Wed, 30 Apr 2025 at 23:43, David Rowley wrote: > memcpy() would make more sense IMO, since the length is > known already. I'm fine with either, however. In case you're looking for inspiration on a standard to follow, commits such as 586dd5d6a did seem to favour memcpy() when the length was kno

Re: pgsql: Add missing string terminator

2025-04-30 Thread David Rowley
On Wed, 30 Apr 2025 at 23:27, Daniel Gustafsson wrote: > How about using strlcpy as suggested by Peter? > > - strncpy(nameptr, "Remaining Totals", namelen); > - nameptr[namelen] = '\0'; > + strlcpy(nameptr, "Remaining Totals", namel

Re: pgsql: Add missing string terminator

2025-04-30 Thread Daniel Gustafsson
> On 30 Apr 2025, at 12:57, David Rowley wrote: > > On Wed, 30 Apr 2025 at 21:36, Daniel Gustafsson > wrote: >> Add missing string terminator > > A possible minor niggle. Would memcpy not be a more suitable function > for this? How about using strlcpy as suggested by Peter? -

Re: pgsql: Add missing string terminator

2025-04-30 Thread David Rowley
On Wed, 30 Apr 2025 at 21:36, Daniel Gustafsson wrote: > Add missing string terminator A possible minor niggle. Would memcpy not be a more suitable function for this? It's just there've been a few efforts in the past to try and minimise the usage of strncpy(). There should really just be a smal

pgsql: Add missing string terminator

2025-04-30 Thread Daniel Gustafsson
Add missing string terminator When copying the string strncpy won't add nul termination since the string length is equal to the length specified. Explicitly set a nul terminator after copying to properly terminate. Found via post-commit review. Author: Rahila Syed Reviewed-by: Daniel Gustafsson