AF:
NF:0
PS:10
SRH:1
SFN:
DSR:
MID:<20080118113526.06f8e3d4@ripper.onstor.net>
CFG:
PT:0
S:andy.sharp@onstor.com
RQ:
SSV:onstor-exch02.onstor.net
NSV:
SSH:
R:<james.kahn@onstor.com>,<dl-software@onstor.com>
MAID:1
X-Sylpheed-Privacy-System:
X-Sylpheed-Sign:0
SCF:#mh/Mailbox/sent
RMID:#imap/andys@onstor.net@onstor-exch02.onstor.net/INBOX	0	BB375AF679D4A34E9CA8DFA650E2B04E038F8F00@onstor-exch02.onstor.net
X-Sylpheed-End-Special-Headers: 1
Date: Fri, 18 Jan 2008 11:35:53 -0800
From: Andrew Sharp <andy.sharp@onstor.com>
To: "James Kahn" <james.kahn@onstor.com>
Cc: "dl-Software" <dl-software@onstor.com>
Subject: Re: Use strlcpy instead of strncpy
Message-ID: <20080118113553.6aa281e9@ripper.onstor.net>
In-Reply-To: <BB375AF679D4A34E9CA8DFA650E2B04E038F8F00@onstor-exch02.onstor.net>
References: <BB375AF679D4A34E9CA8DFA650E2B04E038F8F00@onstor-exch02.onstor.net>
Organization: Onstor
X-Mailer: Sylpheed-Claws 2.6.0 (GTK+ 2.8.20; x86_64-pc-linux-gnu)
Mime-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit

On Fri, 18 Jan 2008 11:31:12 -0800 "James Kahn" <james.kahn@onstor.com>
wrote:

> I thought I'd mention that a more efficient string function exists for
> dealing with strncpy()
> Coverity limitations, strlcpy().  Strlcpy always NULL terminates the
> destination string
> unlike strncpy() which will not NULL terminate if the source string is
> bigger than the 
> destination string.
> 
> Here is the Converity band-aid, that has been been used to date:
>         strncpy(asCfg.to, entry->value, sizeof(asCfg.to) - 1);
>         asCfg.to[sizeof(asCfg.to) - 1] = '\0';
> 
> Following is the strlcpy() solution:
>         strlcpy(asCfg.to, entry->value, sizeof(asCfg.to));
> 
> 
> fyi,
> --Jim

Thanks for informing on this one, Jim.  I've always hated the strncpy
semantics and despaired at the 5 trillion instances of code like your
example.

Cheers,

a
