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: "Carlos O'Donell (Code Review)" <gerrit at gnutoolchain-gerrit dot osci dot io>
- To: Florian Weimer <fweimer at redhat dot com>, libc-alpha at sourceware dot org
- Date: Wed, 27 Nov 2019 14:08:06 -0500
- Subject: [review] manual: Clarify strnlen, wcsnlen, strndup null termination behavior
- Auto-submitted: auto-generated
- References: <gerrit.1572431114000.Ia3e68bc2d4d7e967df141702fb2f600cbd4a6432@gnutoolchain-gerrit.osci.io>
- Reply-to: gnutoolchain-gerrit at osci dot io
Carlos O'Donell has posted comments on this change.
Change URL: https://gnutoolchain-gerrit.osci.io/r/c/glibc/+/444
......................................................................
Patch Set 1: Code-Review+2
(2 comments)
Looks good to me.
Reivewed-by: Carlos O'Donell <carlos@redhat.com>
| --- /dev/null
| +++ /COMMIT_MSG
| @@ -1,0 +1,12 @@
| +Parent: 177a3d48 (y2038: linux: Provide __clock_getres64 implementation)
| +Author: Florian Weimer <fweimer@redhat.com>
| +AuthorDate: 2019-10-30 11:21:18 +0100
| +Commit: Florian Weimer <fweimer@redhat.com>
| +CommitDate: 2019-10-30 11:21:18 +0100
| +
| +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.
PS1, Line 10:
OK. Agreed.
| +
| +Change-Id: Ia3e68bc2d4d7e967df141702fb2f600cbd4a6432
| --- manual/string.texi
| +++ manual/string.texi
| @@ -321,18 +321,22 @@ is more efficient and works even if @var{s} is not null-terminated so
| long as @var{maxlen} does not exceed the size of @var{s}'s array.
|
| @smallexample
| char string[32] = "hello, world";
| strnlen (string, 32)
| @result{} 12
| strnlen (string, 5)
| @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.
PS1, Line 333:
OK. Agreed, you must have at least maxlen bytes, othewise it's
undefined. We might even create something that scans backwards for
NULL bytes knowing we have maxlen bytes.
| +
| This function is a GNU extension and is declared in @file{string.h}.
| @end deftypefun
|
| @deftypefun size_t wcsnlen (const wchar_t *@var{ws}, size_t @var{maxlen})
| @standards{GNU, wchar.h}
| @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.
--
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-Reviewer: Carlos O'Donell <carlos@redhat.com>
Gerrit-Comment-Date: Wed, 27 Nov 2019 19:08:06 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment