linux-man.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* readlink
@ 2020-12-24 17:52 Jonny Grant
  2020-12-30 13:56 ` readlink Michael Kerrisk (man-pages)
  0 siblings, 1 reply; 3+ messages in thread
From: Jonny Grant @ 2020-12-24 17:52 UTC (permalink / raw)
  To: linux-man; +Cc: Michael Kerrisk

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);
"

Kind regards
Jonny

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

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

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-24 17:52 readlink Jonny Grant
2020-12-30 13:56 ` readlink Michael Kerrisk (man-pages)
2021-01-02 21:15   ` readlink Jonny Grant

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).