linux-man.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] getline.3: !*lineptr is sufficient
@ 2021-05-19 10:38 наб
  2021-05-21 10:15 ` Alejandro Colomar (man-pages)
  0 siblings, 1 reply; 2+ messages in thread
From: наб @ 2021-05-19 10:38 UTC (permalink / raw)
  To: Alejandro Colomar; +Cc: linux-man

[-- Attachment #1: Type: text/plain, Size: 1439 bytes --]

No implementation or spec requires *n to be 0 to allocate a new buffer:
  * musl checks for !*lineptr
    (and sets *n=0 for later allocations)
  * glibc checks for !*lineptr || !*n
    (but only because it allocates early)
  * NetBSD checks for !*lineptr
    (and sets *n=0 for later allocations)
    (but specifies *n => mlen(*lineptr) >= *n as a precondition,
     to which this appears to be an exception)
  * FreeBSD checks for !*lineptr and sets *n=0
    (and specifies !*lineptr as sufficient)
  * Lastly, POSIX.1-2017 specifies:
    > If *n is non-zero, the application shall ensure that *lineptr
    > either points to an object of size at least *n bytes,
    > or is a null pointer.

The new wording matches POSIX, even if it arrives at the point slightly
differently

Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz>
---
I seem to've blundered actually adding the page update in v1, sorry!

 man3/getline.3 | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/man3/getline.3 b/man3/getline.3
index a32d7e770..6641ecc35 100644
--- a/man3/getline.3
+++ b/man3/getline.3
@@ -59,9 +59,7 @@ one was found.
 .PP
 If
 .I "*lineptr"
-is set to NULL and
-.I *n
-is set 0 before the call, then
+is set to NULL before the call, then
 .BR getline ()
 will allocate a buffer for storing the line.
 This buffer should be freed by the user program
-- 
2.20.1

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] getline.3: !*lineptr is sufficient
  2021-05-19 10:38 [PATCH v2] getline.3: !*lineptr is sufficient наб
@ 2021-05-21 10:15 ` Alejandro Colomar (man-pages)
  0 siblings, 0 replies; 2+ messages in thread
From: Alejandro Colomar (man-pages) @ 2021-05-21 10:15 UTC (permalink / raw)
  To: наб; +Cc: linux-man

Hi Ahelenia,

On 5/19/21 12:38 PM, наб wrote:
> No implementation or spec requires *n to be 0 to allocate a new buffer:
>    * musl checks for !*lineptr
>      (and sets *n=0 for later allocations)
>    * glibc checks for !*lineptr || !*n
>      (but only because it allocates early)
>    * NetBSD checks for !*lineptr
>      (and sets *n=0 for later allocations)
>      (but specifies *n => mlen(*lineptr) >= *n as a precondition,
>       to which this appears to be an exception)
>    * FreeBSD checks for !*lineptr and sets *n=0
>      (and specifies !*lineptr as sufficient)
>    * Lastly, POSIX.1-2017 specifies:
>      > If *n is non-zero, the application shall ensure that *lineptr
>      > either points to an object of size at least *n bytes,
>      > or is a null pointer.
> 
> The new wording matches POSIX, even if it arrives at the point slightly
> differently
> 
> Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz>

Patch applied, Thanks.

Cheers,

Alex

> ---
> I seem to've blundered actually adding the page update in v1, sorry!
> 
>   man3/getline.3 | 4 +---
>   1 file changed, 1 insertion(+), 3 deletions(-)
> 
> diff --git a/man3/getline.3 b/man3/getline.3
> index a32d7e770..6641ecc35 100644
> --- a/man3/getline.3
> +++ b/man3/getline.3
> @@ -59,9 +59,7 @@ one was found.
>   .PP
>   If
>   .I "*lineptr"
> -is set to NULL and
> -.I *n
> -is set 0 before the call, then
> +is set to NULL before the call, then
>   .BR getline ()
>   will allocate a buffer for storing the line.
>   This buffer should be freed by the user program
> 


-- 
Alejandro Colomar
Linux man-pages comaintainer; https://www.kernel.org/doc/man-pages/
Senior SW Engineer; http://www.alejandro-colomar.es/

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-05-21 10:16 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-19 10:38 [PATCH v2] getline.3: !*lineptr is sufficient наб
2021-05-21 10:15 ` Alejandro Colomar (man-pages)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).