Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 23 Jul 2013 18:51:00 +0400 (MSK)
From:      Dmitry Marakasov <amdmi3@FreeBSD.org>
To:        FreeBSD-gnats-submit@freebsd.org
Subject:   docs/180767: [man][libc] printf.3: fix off-by-one in snprintf description
Message-ID:  <20130723145100.67AF354E@hades.panopticon>
Resent-Message-ID: <201307231510.r6NFA0WK020494@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         180767
>Category:       docs
>Synopsis:       [man][libc] 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:
>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:
>Unformatted:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20130723145100.67AF354E>