From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 103925 invoked by alias); 30 Oct 2019 11:00:06 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Received: (qmail 103872 invoked by uid 89); 30 Oct 2019 11:00:04 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-2.8 required=5.0 tests=AWL,BAYES_00,SPF_PASS autolearn=ham version=3.3.1 spammy=H*f:sk:87a79i3, H*i:sk:87a79i3 X-HELO: mx1.suse.de From: Andreas Schwab To: Florian Weimer Cc: libc-alpha@sourceware.org Subject: Re: [review] manual: Clarify strnlen, wcsnlen, strndup null termination behavior References: <87a79i33kt.fsf@oldenburg2.str.redhat.com> X-Yow: Two LITTLE black dots and one BIG black dot...nice 'n' FLUFFY!! Date: Wed, 30 Oct 2019 11:00:00 -0000 In-Reply-To: <87a79i33kt.fsf@oldenburg2.str.redhat.com> (Florian Weimer's message of "Wed, 30 Oct 2019 11:55:30 +0100") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-SW-Source: 2019-10/txt/msg00913.txt.bz2 On Okt 30 2019, Florian Weimer wrote: > * Andreas Schwab: > >> On Okt 30 2019, Florian Weimer (Code Review) wrote: >> >>> +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 is not true. strnlen _always_ stops before the null byte. > > This is not how it is specified in POSIX. Yes, it is. The strnlen() function shall return the number of bytes preceding the first null byte in the array to which s points, if s contains a null byte within the first maxlen bytes; otherwise, it shall return maxlen. There is nothing undefined here. Your interpretation would be completely useless anyway. Andreas. -- Andreas Schwab, SUSE Labs, schwab@suse.de GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE 1748 E4D4 88E3 0EEA B9D7 "And now for something completely different."