From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:34430) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SS38C-00063V-So for qemu-devel@nongnu.org; Wed, 09 May 2012 05:24:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SS385-0002Aw-My for qemu-devel@nongnu.org; Wed, 09 May 2012 05:24:24 -0400 Received: from mx.meyering.net ([88.168.87.75]:36917) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SS385-000243-DC for qemu-devel@nongnu.org; Wed, 09 May 2012 05:24:17 -0400 From: Jim Meyering Date: Wed, 9 May 2012 11:24:06 +0200 Message-Id: <1336555446-20180-23-git-send-email-jim@meyering.net> In-Reply-To: <1336555446-20180-1-git-send-email-jim@meyering.net> References: <1336555446-20180-1-git-send-email-jim@meyering.net> Subject: [Qemu-devel] [PATCH 22/22] 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 , Blue Swirl , Anthony Liguori , Stefan Hajnoczi , Peter Maydell 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.7.10.1.487.ga3935e6