manual: clarify buffer behavior in getline
diff mbox

Message ID 1396430311-1158-1-git-send-email-vapier@gentoo.org
State Accepted, archived
Headers show

Commit Message

Mike Frysinger April 2, 2014, 9:18 a.m. UTC
From: David Svoboda <svoboda@cert.org>

If the user has requested automatic buffer creation, getline may create
it and not free things when an error occurs.  That means the user is
always responsible for calling free() regardless of the return value.

The current documentation does not explicitly cover this which leaves it
slightly ambiguous to the reader.  So clarify things.

2014-04-02  David Svoboda  <svoboda@cert.org>

	* manual/stdio.texi (Line-Oriented Input): Document buffer allocation
	explicitly.
---
 manual/stdio.texi | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Roland McGrath April 3, 2014, 5:38 p.m. UTC | #1
>  If you set @code{*@var{lineptr}} to a null pointer, and @code{*@var{n}}
>  to zero, before the call, then @code{getline} allocates the initial
> -buffer for you by calling @code{malloc}.
> +buffer for you by calling @code{malloc}. This buffer remains allocated

Two spaces.

Otherwise fine.
Mike Frysinger April 3, 2014, 10:28 p.m. UTC | #2
On Thu 03 Apr 2014 10:38:43 Roland McGrath wrote:
> >  If you set @code{*@var{lineptr}} to a null pointer, and @code{*@var{n}}
> >  to zero, before the call, then @code{getline} allocates the initial
> > 
> > -buffer for you by calling @code{malloc}.
> > +buffer for you by calling @code{malloc}. This buffer remains allocated
> 
> Two spaces.
> 
> Otherwise fine.

fixed & pushed
-mike

Patch
diff mbox

diff --git a/manual/stdio.texi b/manual/stdio.texi
index a4364f7..db55f05 100644
--- a/manual/stdio.texi
+++ b/manual/stdio.texi
@@ -1298,7 +1298,8 @@  back in @code{*@var{n}}.
 
 If you set @code{*@var{lineptr}} to a null pointer, and @code{*@var{n}}
 to zero, before the call, then @code{getline} allocates the initial
-buffer for you by calling @code{malloc}.
+buffer for you by calling @code{malloc}. This buffer remains allocated
+even if @code{getline} encounters errors and is unable to read any bytes.
 
 In either case, when @code{getline} returns,  @code{*@var{lineptr}} is
 a @code{char *} which points to the text of the line.