From: "Michael Kerrisk (man-pages)" <mtk.manpages@gmail.com>
To: Jonny Grant <jg@jguk.org>, linux-man <linux-man@vger.kernel.org>
Cc: mtk.manpages@gmail.com
Subject: Re: readlink
Date: Wed, 30 Dec 2020 14:56:47 +0100 [thread overview]
Message-ID: <63d3bfdc-93dd-6f3e-8ed4-7036b01f9751@gmail.com> (raw)
In-Reply-To: <79e09e31-c33e-3fbf-158b-30344e7aae68@jguk.org>
Hello Jonny,
On 12/24/20 6:52 PM, Jonny Grant wrote:
> Seasons greetings Michael,
>
> May I ask, could readlink be updated to use the same wording for null
> termination like on sprintf, scanf etc?
>
> https://man7.org/linux/man-pages/man2/readlink.2.html
>
> It says:
> "readlink() does not append a null byte to buf"
>
> Perhaps it should say:
> "readlink() does not append a terminating null byte to buf ('\0')"
>
> In addition, is it worth adding a BUGS section to remind that there
> is no terminating null byte?
>
> "readlink() assumes the caller understands that no terminating null
> byte ('\0') will be written in the provided buf. If the caller didn't
> memset the buffer to ('\0') or allocate an extra byte for the
> terminating null byte, there is a risk the caller could overrun the
> end of the buffer, or use uninitialised values in the buf."
>
> Finally, perhaps also the EXAMPLES program could be updated to clarify this:
>
> "/* print only nbytes of buf, as it doesn't contain a terminating null byte ('\0') */
> printf("'%s' points to '%.*s'\n", argv[1], (int) nbytes, buf);
> "
I think that having (1) the existing statement at the start of the
DESCRIPTION, (2) adding a comment to the code, and (3) adding a BUGS
section all to cover the same point seems a little excessive.
I've gone for 2 out of 3.
Thanks,
Michael
--- a/man2/readlink.2
+++ b/man2/readlink.2
@@ -93,7 +93,7 @@ in the buffer
which has size
.IR bufsiz .
.BR readlink ()
-does not append a null byte to
+does not append a terminating null byte to
.IR buf .
It will (silently) truncate the contents (to a length of
.I bufsiz
@@ -332,6 +332,8 @@ main(int argc, char *argv[])
exit(EXIT_FAILURE);
}
+ /* Print only \(aqnbytes\(aq of \(aqbuf\(aq, as it doesn't contain a terminating
+ null byte (\(aq\e0\(aq). */
printf("\(aq%s\(aq points to \(aq%.*s\(aq\en", argv[1], (int) nbytes, buf);
/* If the return value was equal to the buffer size, then the
--
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
Linux/UNIX System Programming Training: http://man7.org/training/
next prev parent reply other threads:[~2020-12-30 13:57 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-24 17:52 readlink Jonny Grant
2020-12-30 13:56 ` Michael Kerrisk (man-pages) [this message]
2021-01-02 21:15 ` readlink Jonny Grant
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=63d3bfdc-93dd-6f3e-8ed4-7036b01f9751@gmail.com \
--to=mtk.manpages@gmail.com \
--cc=jg@jguk.org \
--cc=linux-man@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.