From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16683 invoked by alias); 12 Apr 2017 15:24:46 -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 9832 invoked by uid 89); 12 Apr 2017 15:24:39 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.1 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,RCVD_IN_SORBS_SPAM,SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mout.gmx.net Subject: Re: [PATCH] Add reallocarray function. To: Florian Weimer , libc-alpha@sourceware.org References: <20170410150053.10208-1-denniswoelfing@gmx.de> From: =?UTF-8?Q?Dennis_W=c3=b6lfing?= Message-ID: <7bccc976-7a3e-4ffa-5e2c-767f3e3c9658@gmx.de> Date: Wed, 12 Apr 2017 15:24:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-UI-Out-Filterresults: notjunk:1;V01:K0:UkhhoRSwIDo=:4dTN6JBF0v6QxajDn85Ov4 zc8qpQFEYDI7n3TPOthdL7XdtMbZ3akNlvcnPaKlTF5DiR+rpLBVqncYdFFYdSl2doVkZfKxH p5jt5uBMITSy8I0rFNcgOyIrILTeD2AXU+7JGzyoQFIUYC9NUaog3Q3ZSSk0/gJch1LuCzsxM mSW4eu/lhhniHCpQD0etQEGE60TF0PiQy6EIWQ/kjDIshRZZwU/tNMZOri/Q1JRkl4CjejB9e dcIyo2xGnEukEhDrDApUPQd1hWqv8y0lnVrplCh8AngsC5FYeS6XDUlwdjnsFWW8qRhOxABDE uQSHOg2FtX9hXmmvZA+4FdApbPB1ZAtoD7qYhUF1WwwAEKn3XRaEh6Skvczg21rm1LARg+ccb XB6FcnnPXAhvJt0rXgkbFHSP88jJK/Xj0DiyKL2x34EtTyQeYmoolgKEwadqN1DAshNN6h2NK XwMgO33IbjbY6q9vHDsQrYnoJzTyf9yHQQPiZZBopm+TXY2Vfl53s2vedeEbZwgebWyQ32k4g rbJ2xCCU41bZ+/tbIoZn1lq25qPbzT4U9tnWaFyW3cXngMBKxJioEdovQtJxw15iZ0lDGqlxy Uh3JVDm+mXyKGV2vTOM7hsm6fBTIoOw/MkQs/JIXFGagkQOX475E20uvPxw+PnXCmdfWl+yN7 rmjrGGdy4faQDylV0wQBRUFMO2sqhxvlcmTZ3XP7I5VYYlaamJDPy1QPeehXuMbCfL2KYkIsa Tjq6nBcZoscmbUvCv62DHWCE3n4RHHL9GsZyaEohb9JTTL97us/DVFUIDAiNUG1bBy6+yXr5L mMKL4Od X-SW-Source: 2017-04/txt/msg00217.txt.bz2 On 11.04.2017 09:55, Florian Weimer wrote: > On 04/10/2017 05:00 PM, Dennis Wölfing wrote: >> +void * >> +__libc_reallocarray(void *optr, size_t nmemb, size_t elem_size) >> +{ >> + INTERNAL_SIZE_T bytes; >> + if (check_mul_overflow(nmemb, elem_size, &bytes)) >> + { >> + __set_errno (ENOMEM); >> + return 0; >> + } >> + else >> + return __libc_realloc (optr, bytes); >> +} > > This needs to go into its own file and has to call realloc (not > __libc_realloc), otherwise it will not be compatible with malloc > interposition. Ok, I see the problem. When a statically linked program defines their own memory allocation functions, calls to reallocarray pull in malloc.c and thus cause link errors. The static inline function check_mul_overflow is used in both reallocarray and calloc. So that function would need to be in a file that can be included by both malloc.c and a new reallocarray.c file. Would malloc-internal.h be a good location to put that inline function or should I place it into its own separate file?