From amdmi3@amdmi3.ru  Tue Jul 23 15:07:06 2013
Return-Path: <amdmi3@amdmi3.ru>
Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115])
	by hub.freebsd.org (Postfix) with ESMTP id 24B40310
	for <freebsd-gnats-submit@freebsd.org>; Tue, 23 Jul 2013 15:07:06 +0000 (UTC)
	(envelope-from amdmi3@amdmi3.ru)
Received: from smtp.timeweb.ru (smtp.timeweb.ru [92.53.116.43])
	(using TLSv1.2 with cipher DHE-RSA-AES128-SHA (128/128 bits))
	(No client certificate requested)
	by mx1.freebsd.org (Postfix) with ESMTPS id D984F2314
	for <freebsd-gnats-submit@freebsd.org>; Tue, 23 Jul 2013 15:07:05 +0000 (UTC)
Received: from [213.148.20.85] (helo=hive.panopticon)
	by smtp.timeweb.ru with esmtpsa (TLS1.0:DHE_RSA_CAMELLIA_256_CBC_SHA1:256)
	(Exim 4.80)
	(envelope-from <amdmi3@amdmi3.ru>)
	id 1V1dvZ-00012p-Ba
	for FreeBSD-gnats-submit@freebsd.org; Tue, 23 Jul 2013 18:51:01 +0400
Received: from hades.panopticon (hades.panopticon [192.168.0.32])
	by hive.panopticon (Postfix) with ESMTP id 89B8E955
	for <FreeBSD-gnats-submit@freebsd.org>; Tue, 23 Jul 2013 18:51:00 +0400 (MSK)
Received: by hades.panopticon (Postfix, from userid 1000)
	id 67AF354E; Tue, 23 Jul 2013 18:51:00 +0400 (MSK)
Message-Id: <20130723145100.67AF354E@hades.panopticon>
Date: Tue, 23 Jul 2013 18:51:00 +0400 (MSK)
From: Dmitry Marakasov <amdmi3@FreeBSD.org>
Reply-To: Dmitry Marakasov <amdmi3@FreeBSD.org>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: [man][libc] printf.3: fix off-by-one in snprintf description
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         180767
>Category:       docs
>Synopsis:       [patch] printf.3: fix off-by-one in snprintf description
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-doc
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          doc-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue Jul 23 15:10:00 UTC 2013
>Closed-Date:    
>Last-Modified:  Mon Jul 29 01:31:24 UTC 2013
>Originator:     Dmitry Marakasov
>Release:        FreeBSD 9.1-RELEASE-p4 amd64
>Organization:
>Environment:
System: FreeBSD hades.panopticon 9.1-RELEASE-p4 FreeBSD 9.1-RELEASE-p4 #0 r251956: Tue Jun 18 21:41:37 MSK 2013 root@hades.panopticon:/usr/obj/usr/src/sys/HADES amd64


>Description:
printf(3) says for snprintf:

     The snprintf() and vsnprintf() functions will write at most size-1 of the
     characters printed into the output string (the size'th character then
     gets the terminating `\0');

the part in parenteses is incorrect: size'th character is outside
buffer of [size] characters. It should instead say "(size-1)'th
character" (which is last in the buffer).

>How-To-Repeat:
>Fix:

--- printf.3.patch begins here ---
Index: lib/libc/stdio/printf.3
===================================================================
--- lib/libc/stdio/printf.3	(revision 253572)
+++ lib/libc/stdio/printf.3	(working copy)
@@ -143,7 +143,7 @@
 .Fa size Ns \-1
 of the characters printed into the output string
 (the
-.Fa size Ns 'th
+.Fa ( size Ns \-1)'th
 character then gets the terminating
 .Ql \e0 ) ;
 if the return value is greater than or equal to the
--- printf.3.patch ends here ---

>Release-Note:
>Audit-Trail:

From: Benjamin Kaduk <kaduk@MIT.EDU>
To: bug-followup@freebsd.org
Cc:  
Subject: Re: docs/180767: [man][libc] printf.3: fix off-by-one in snprintf
 description
Date: Tue, 23 Jul 2013 17:07:02 -0400 (EDT)

 On Tue, 23 Jul 2013, Dmitry Marakasov wrote:
 
 >
 >
 >> Description:
 > printf(3) says for snprintf:
 >
 >     The snprintf() and vsnprintf() functions will write at most size-1 of the
 >     characters printed into the output string (the size'th character then
 >     gets the terminating `\0');
 >
 > the part in parenteses is incorrect: size'th character is outside
 > buffer of [size] characters. It should instead say "(size-1)'th
 > character" (which is last in the buffer).
 
 I think one could argue either way.  The character with index (size-1) 
 gets the NUL byte, but if one says that the first character is the one 
 with index 0, then it is in fact the size'th character which receives the 
 NUL.
 
 -Ben Kaduk
>Unformatted:
