This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[review] manual: Clarify strnlen, wcsnlen, strndup null termination behavior
- From: "Florian Weimer (Code Review)" <gerrit at gnutoolchain-gerrit dot osci dot io>
- To: libc-alpha at sourceware dot org
- Date: Wed, 30 Oct 2019 06:25:15 -0400
- Subject: [review] manual: Clarify strnlen, wcsnlen, strndup null termination behavior
- Auto-submitted: auto-generated
- References: <gerrit.1572431114000.Ia3e68bc2d4d7e967df141702fb2f600cbd4a6432@gnutoolchain-gerrit.osci.io>
- Reply-to: fweimer at redhat dot com, libc-alpha at sourceware dot org
Change URL: https://gnutoolchain-gerrit.osci.io/r/c/glibc/+/444
......................................................................
manual: Clarify strnlen, wcsnlen, strndup null termination behavior
It is required that the inputs are arrays, as reading is not
guaranteed to stop on the first null byte.
Change-Id: Ia3e68bc2d4d7e967df141702fb2f600cbd4a6432
---
M manual/string.texi
1 file changed, 10 insertions(+), 0 deletions(-)
diff --git a/manual/string.texi b/manual/string.texi
index a1c58e5..ba8a588 100644
--- a/manual/string.texi
+++ b/manual/string.texi
@@ -328,6 +328,10 @@
@result{} 5
@end smallexample
+Note that @var{s} must be an array of at least @var{maxlen} bytes. It
+is undefined to call @code{strnlen} on a shorter array, even if it is
+known that the shorter array contains a null terminator.
+
This function is a GNU extension and is declared in @file{string.h}.
@end deftypefun
@@ -336,6 +340,8 @@
@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
@code{wcsnlen} is the wide character equivalent to @code{strnlen}. The
@var{maxlen} parameter specifies the maximum number of wide characters.
+Similar to @code{strnlen}, @var{ws} must point to an array of at least
+@var{maxlen} wide characters.
This function is a GNU extension and is declared in @file{wchar.h}.
@end deftypefun
@@ -919,6 +925,10 @@
copies just the first @var{size} bytes and adds a closing null byte.
Otherwise all bytes are copied and the string is terminated.
+Note that @var{s} must be an array of at least @var{size} bytes. It
+is undefined to call @code{strndup} on a shorter array, even if it is
+known that the shorter array contains a null terminator.
+
This function differs from @code{strncpy} in that it always terminates
the destination string.
--
Gerrit-Project: glibc
Gerrit-Branch: master
Gerrit-Change-Id: Ia3e68bc2d4d7e967df141702fb2f600cbd4a6432
Gerrit-Change-Number: 444
Gerrit-PatchSet: 1
Gerrit-Owner: Florian Weimer <fweimer@redhat.com>
Gerrit-MessageType: newchange