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

From David Rowley
Subject Re: pgsql: Add missing string terminator
Date
Msg-id CAApHDvrg3Gz6kF76Feyc6Dyi9u7iS+vcdQw3VZgGA1+wUc=wRQ@mail.gmail.com
Whole thread Raw
In response to pgsql: Add missing string terminator  (Daniel Gustafsson <dgustafsson@postgresql.org>)
Responses Re: pgsql: Add missing string terminator
List pgsql-committers
On Wed, 30 Apr 2025 at 21:36, Daniel Gustafsson
<dgustafsson@postgresql.org> 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
small handful of cases where the strange behaviour of that function is
needed. I don't think this is one of those cases.

Maybe something like the following would suit better?

#define REMAINING_TOTALS "Remaining Totals"
    num_individual_stats = context_id + 1;
    meminfo[max_stats - 1].name = dsa_allocate(MemoryStatsDsaArea,
sizeof(REMAINING_TOTALS));
    nameptr = dsa_get_address(MemoryStatsDsaArea, meminfo[max_stats - 1].name);
    memcpy(nameptr, REMAINING_TOTALS, sizeof(REMAINING_TOTALS));

David



pgsql-committers by date:

Previous
From: Daniel Gustafsson
Date:
Subject: pgsql: Typo and doc fixups for memory context reporting
Next
From: Daniel Gustafsson
Date:
Subject: Re: pgsql: Add missing string terminator