From patchwork Wed Oct 30 10:25:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Simon Marchi (Code Review)" X-Patchwork-Id: 35467 Received: (qmail 4646 invoked by alias); 30 Oct 2019 10:25:21 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 4632 invoked by uid 89); 30 Oct 2019 10:25:20 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3 autolearn=ham version=3.3.1 spammy=termination, smallexample, @var X-HELO: mx1.osci.io X-Gerrit-PatchSet: 1 Date: Wed, 30 Oct 2019 06:25:15 -0400 From: "Florian Weimer (Code Review)" To: libc-alpha@sourceware.org Message-ID: Auto-Submitted: auto-generated X-Gerrit-MessageType: newchange Subject: [review] manual: Clarify strnlen, wcsnlen, strndup null termination behavior X-Gerrit-Change-Id: Ia3e68bc2d4d7e967df141702fb2f600cbd4a6432 X-Gerrit-Change-Number: 444 X-Gerrit-ChangeURL: X-Gerrit-Commit: 7eb8ae69a93874313a95c27985ed2441d74de3af References: Reply-To: fweimer@redhat.com, libc-alpha@sourceware.org MIME-Version: 1.0 Content-Disposition: inline User-Agent: Gerrit/3.0.3-74-g460fb0f7e9 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.