From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 77150 invoked by alias); 5 Apr 2018 10:08:50 -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 77141 invoked by uid 89); 5 Apr 2018 10:08:50 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_PASS,T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=Hx-languages-length:748 X-HELO: mx2.suse.de From: Andreas Schwab To: Florian Weimer Cc: libc-alpha@sourceware.org Subject: Re: [PATCH] manual: Various fixes to the mbstouwcs example References: <20180404135740.A283E406F5A23@oldenburg.str.redhat.com> <9158a888-c5c4-729f-c897-6b995979f1b7@redhat.com> X-Yow: BARBARA STANWYCK makes me nervous!! Date: Thu, 05 Apr 2018 10:08:00 -0000 In-Reply-To: <9158a888-c5c4-729f-c897-6b995979f1b7@redhat.com> (Florian Weimer's message of "Thu, 5 Apr 2018 11:56:39 +0200") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.91 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-SW-Source: 2018-04/txt/msg00138.txt.bz2 On Apr 05 2018, Florian Weimer wrote: > @@ -7,22 +8,46 @@ > wchar_t * > mbstouwcs (const char *s) > { > - size_t len = strlen (s); > - wchar_t *result = malloc ((len + 1) * sizeof (wchar_t)); > + /* Include the NUL terminator in the conversion. */ > + size_t len = strlen (s) + 1; > + wchar_t *result = reallocarray (NULL, len + 1, sizeof (wchar_t)); I still think that result[len] is never used. The conversion of a multibyte string with len bytes can generate at most len wide characters. 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."