From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-il1-x12d.google.com (mail-il1-x12d.google.com [IPv6:2607:f8b0:4864:20::12d]) by sourceware.org (Postfix) with ESMTPS id 0CC0A385800B for ; Mon, 11 Jan 2021 10:13:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 0CC0A385800B Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=josttech.ch Authentication-Results: sourceware.org; spf=none smtp.mailfrom=johannes.pfister@josttech.ch Received: by mail-il1-x12d.google.com with SMTP id x15so17832779ilq.1 for ; Mon, 11 Jan 2021 02:13:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=josttech-ch.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=FDdlkIY2G1OExobX1qgXIDcF6z94Xb7wteF/VcHZU2M=; b=BJUNiWo/jGRE7hbWMvuycK8okbwRYkFEfarFMwyL3dPG8JQO3b+1HhBu98Gp4R+Gfk +gi7/5w5yo1GZLauzvBaxEX1nqkBxfrXMbXpJQm+mRG1pBZiL0K6COdLnm0PUd46H018 TjkVDMynt5WXsiYd//H3z3vBKIFTwlqPXI7cv4GeQLvTSJdtSD3Ed+GrIQyX+hAJGvFl 0LgjSOssj5GGzt2WvrAZ4VHTEsTGj1B7oo5/Q7wtakv8Gx3bUSqyW36AJgVdvFVAcf4S xFenm9J1Q2wrffGq2zxDycu01MtkfKJ/ThVyj9W5PdtwwkMIsQNkokwXnKSohZD+BYM7 Yk4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=FDdlkIY2G1OExobX1qgXIDcF6z94Xb7wteF/VcHZU2M=; b=S0drpJrvknjV8xZ/y/G4AJ9ZtQngDyDO29PTqmpTFZT8fhKQiRZo+ytNUUQvLErUOg t7X2S1p6EJH2g582meKORO8/NM2CyFY46ydhu96AWy+AGFeTHDZ3ZkATzpOcF1afJz9Q eSvk9t2ZCEaoYsaP9fmAZO1HPxvWKTlyw3E4nuXI6KRfRXcH6UCtyGaT/rGtKyVGTrHu eVi3/95ZETIjfNT5ypK1ptGAMT1fvRWMaJa+IW5KoRw3rgo9QOMzLDOMeZskzKboBz3Q W9NEuIUpv5yn8B542LhFtdXiI/0lZet893qtr5cK9tbwaIwcNbPXBG5xPBFW5v68KddO gb9g== X-Gm-Message-State: AOAM533hYHkAVd4NMlQQlj4fFL6BZiSJzya2aG0XW4/LarwIdvnuPC07 CVVMK5EHM7gTMLnuMbUZx0dxrwqUruv72KTUH6DOsA== X-Google-Smtp-Source: ABdhPJwgYwNPlHXTAqJgNeHYPLdrkKSnqv9J8Sn7BrJH8Ejcwo9BgNC512vvvwP7WFRLiVCAhPe7Qr745nD638YYLV4= X-Received: by 2002:a05:6e02:c6a:: with SMTP id f10mr15126684ilj.264.1610359995540; Mon, 11 Jan 2021 02:13:15 -0800 (PST) MIME-Version: 1.0 References: <20210109211505.76000-1-alx.manpages@gmail.com> In-Reply-To: <20210109211505.76000-1-alx.manpages@gmail.com> From: Johannes Pfister Date: Mon, 11 Jan 2021 10:13:03 +0000 Message-ID: Subject: Re: [PATCH, BUG 211039] malloc.3: Document that realloc(p, 0) is specific to glibc and nonportable To: alx.manpages@gmail.com Cc: linux-man@vger.kernel.org, bugzilla-daemon@bugzilla.kernel.org, libc-alpha@sourceware.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-11.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_NONE, TXREP, URI_DOTEDU autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 11 Jan 2021 10:13:17 -0000 > A more detailed notice is on realloc(3p). Yes. But i think it will lead to bugs when there is a documentation that describes the behavior of realloc(), says realloc(ptr,0) will do free(ptr), says realloc() is conforming to POSIX.1-2001, POSIX.1-2008, C89, C99. But does not mention that the realloc(ptr,0) is not specified in this standards (except C89). And there are some distributions that do not include the realloc(3p) man page. On my Debian Buster (10) there is no realloc(3p) man page and man realloc goes to the malloc man page of the Linux Programmer's Manual. But maybe this is a problem of the distributions/Debian? > Thanks for the report, Johannes! > Please review that your name is correct (I guessed it from the email). Yes it is. Should i configure my name somewhere? Kind Regards Johannes Am Sa., 9. Jan. 2021 um 21:20 Uhr schrieb Alejandro Colomar : > > A more detailed notice is on realloc(3p). > > ...... > > $ man 3p realloc \ > |sed -n \ > -e '/APPLICATION USAGE/,/^$/p' \ > -e '/FUTURE DIRECTIONS/,/^$/p'; > APPLICATION USAGE > The description of realloc() has been modified from pre=E2=80=90 > vious versions of this standard to align with the > ISO/IEC 9899:1999 standard. Previous versions explicitly > permitted a call to realloc(p, 0) to free the space > pointed to by p and return a null pointer. While this be=E2=80=90 > havior could be interpreted as permitted by this version > of the standard, the C language committee have indicated > that this interpretation is incorrect. Applications > should assume that if realloc() returns a null pointer, > the space pointed to by p has not been freed. Since this > could lead to double-frees, implementations should also > set errno if a null pointer actually indicates a failure, > and applications should only free the space if errno was > changed. > > FUTURE DIRECTIONS > This standard defers to the ISO C standard. While that > standard currently has language that might permit real=E2=80=90 > loc(p, 0), where p is not a null pointer, to free p while > still returning a null pointer, the committee responsible > for that standard is considering clarifying the language > to explicitly prohibit that alternative. > > Bug: 211039 > Reported-by: Johannes Pfister > Cc: libc-alpha@sourceware.org > Signed-off-by: Alejandro Colomar > --- > > Hi Johannes, Michael, > > Thanks for the report, Johannes! > Please review that your name is correct (I guessed it from the email). > > Michael, please review the wording. > > Thanks, > > Alex > > man3/malloc.3 | 18 +++++++++++++++++- > 1 file changed, 17 insertions(+), 1 deletion(-) > > diff --git a/man3/malloc.3 b/man3/malloc.3 > index d8b4da62f..467e2438a 100644 > --- a/man3/malloc.3 > +++ b/man3/malloc.3 > @@ -149,7 +149,8 @@ is equal to zero, > and > .I ptr > is not NULL, then the call is equivalent to > -.IR free(ptr) . > +.I free(ptr) > +(this behavior is nonportable; see NOTES). > Unless > .I ptr > is NULL, it must have been returned by an earlier call to > @@ -375,6 +376,21 @@ The > implementation is tunable via environment variables; see > .BR mallopt (3) > for details. > +.SS Nonportable behavior > +The behavior of > +.BR realloc () > +when > +.I size > +is equal to zero, > +and > +.I ptr > +is not NULL, > +is glibc specific; > +other implementations may return NULL, and set > +.IR errno . > +Portable POSIX programs should avoid it. > +See > +.BR realloc (3p). > .SH SEE ALSO > .\" http://g.oswego.edu/dl/html/malloc.html > .\" A Memory Allocator - by Doug Lea > -- > 2.30.0 >