Received: from eggs.gnu.org ([208.118.235.92]:59614) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TJjLF-0002QS-PR for qemu-devel@nongnu.org; Thu, 04 Oct 2012 07:11:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TJjLE-0003UG-N5 for qemu-devel@nongnu.org; Thu, 04 Oct 2012 07:11:45 -0400 Received: from mx.meyering.net ([88.168.87.75]:57052 helo=hx.meyering.net) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TJjLE-0003U3-Ay for qemu-devel@nongnu.org; Thu, 04 Oct 2012 07:11:44 -0400 From: Jim Meyering Date: Thu, 4 Oct 2012 13:10:03 +0200 Message-Id: <1349349003-15672-21-git-send-email-jim@meyering.net> In-Reply-To: <1349349003-15672-1-git-send-email-jim@meyering.net> References: <1349349003-15672-1-git-send-email-jim@meyering.net> Subject: [Qemu-devel] [PATCHv3 20/20] doc: update HACKING wrt strncpy/pstrcpy List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Jim Meyering From: Jim Meyering Reword the section on strncpy: its NUL-filling is important in some cases. Mention that pstrcpy's signature is different. Signed-off-by: Jim Meyering --- HACKING | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/HACKING b/HACKING index 471cf1d..dddd617 100644 --- a/HACKING +++ b/HACKING @@ -91,10 +91,11 @@ emulators. 4. String manipulation -Do not use the strncpy function. According to the man page, it does -*not* guarantee a NULL-terminated buffer, which makes it extremely dangerous -to use. Instead, use functionally equivalent function: -void pstrcpy(char *buf, int buf_size, const char *str) +Do not use the strncpy function. As mentioned in the man page, it does *not* +guarantee a NULL-terminated buffer, which makes it extremely dangerous to use. +It also zeros trailing destination bytes out to the specified length. Instead, +use this similar function when possible, but note its different signature: +void pstrcpy(char *dest, int dest_buf_size, const char *src) Don't use strcat because it can't check for buffer overflows, but: char *pstrcat(char *buf, int buf_size, const char *s) -- 1.8.0.rc0.18.gf84667d