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: "Adhemerval Zanella (Code Review)" X-Patchwork-Id: 1186636 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=libc-alpha-return-106445-incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gnutoolchain-gerrit.osci.io Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="DauRxUt8"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4734N73ZDXz9sPJ for ; Wed, 30 Oct 2019 21:25:27 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:from:to:message-id:subject:references :reply-to:mime-version:content-transfer-encoding:content-type; q=dns; s=default; b=JcRHTSt4fGM0+Gb9hBpGl9rCc4rDdpMw/XJrlkgQGTv +wnWnG0/Yg5DMCFbFMrdmsaw9A2VOXH70uK2yAcQEkPuY8OlFSMhXWkmrwi4Mqyh EBq7zpBAOgeiPCv+blkgvt8kGuGzTBx2cK4i72E9nly7iYRmm/K5CUdFUzQogpik = DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:from:to:message-id:subject:references :reply-to:mime-version:content-transfer-encoding:content-type; s=default; bh=hVr4B/+pmYFNirvX3N0wz0Kkf08=; b=DauRxUt8lSjYFZKkI q6UlCbQStUGr6QpNX85B/VyLeGP3jpJ6mc1oMSjS6vsoeSjz4ulIOxZSuMvWvNMq WRv5VWYmmOIT6/afiyrPr2HcQOy/P9e9AMn9DLgozcohLsk6UlGHJdOGxPWBc8UA qIvD8W5HEEAgBP2nOQn98RUaUo= 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.