Re: Questions/observations about set_ps_display ()

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Strong, David" <david(dot)strong(at)unisys(dot)com>
Cc: "PostgreSQL-development" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Questions/observations about set_ps_display ()
Date: 2006-09-26 16:23:09
Message-ID: 26756.1159287789@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

"Strong, David" <david(dot)strong(at)unisys(dot)com> writes:
> The specification for strncpy () indicates that when the length of the
> source string (4 bytes) is less than the length of the number of bytes
> to copy (2500 bytes), the remainder of the destination string will be
> padded with NULL bytes (2496). Based on the GLIBC source code, strncpy
> () is written to pad the destination string a byte at a time and this is
> where all the time was taken, according to OProfile.

Hm. In the PS_USE_CLOBBER_ARGV case, this is pretty silly considering
we're going to MemSet the rest of the space anyway. We should probably
replace the StrNCpy with something that doesn't uselessly fill the rest
of the buffer, perhaps something like
memcpy(dest, src, Min(strlen(dest) + 1, avail space));

I believe that most of our uses of StrNCpy actually do not expect the
pad-out behavior, so maybe there are other uses for something along
this line ...

regards, tom lane

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2006-09-26 16:24:57 Re: Too many messages from Autovacuum
Previous Message Jeff Frost 2006-09-26 16:17:08 Re: pg_hba.conf: 'trust' vs. 'md5' Issues