Re: pgsql: Add missing string terminator - Mailing list pgsql-committers

From David Rowley
Subject Re: pgsql: Add missing string terminator
Date
Msg-id CAApHDvrEJeCPesmpeS24UAU8vanq9vKYZC6m1kTDFkxQQ2qTiw@mail.gmail.com
Whole thread Raw
In response to Re: pgsql: Add missing string terminator  (Daniel Gustafsson <daniel@yesql.se>)
Responses Re: pgsql: Add missing string terminator
List pgsql-committers
On Wed, 30 Apr 2025 at 23:27, Daniel Gustafsson <daniel@yesql.se> wrote:
> How about using strlcpy as suggested by Peter?
>
> -                       strncpy(nameptr, "Remaining Totals", namelen);
> -                       nameptr[namelen] = '\0';
> +                       strlcpy(nameptr, "Remaining Totals", namelen + 1);

Sorry, I only noticed that conversation afterwards.  Yeah, strlcpy()
is fine too.  memcpy() would make more sense IMO, since the length is
known already. I'm fine with either, however.

David



pgsql-committers by date:

Previous
From: Daniel Gustafsson
Date:
Subject: Re: pgsql: Add missing string terminator
Next
From: David Rowley
Date:
Subject: Re: pgsql: Add missing string terminator