From owner-svn-src-head@FreeBSD.ORG Mon May 5 21:34:03 2014 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 905ADDF9 for ; Mon, 5 May 2014 21:34:03 +0000 (UTC) Received: from mail-pa0-f50.google.com (mail-pa0-f50.google.com [209.85.220.50]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 610EC930 for ; Mon, 5 May 2014 21:34:03 +0000 (UTC) Received: by mail-pa0-f50.google.com with SMTP id fb1so3182586pad.23 for ; Mon, 05 May 2014 14:33:56 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:content-type:mime-version:subject:from :in-reply-to:date:cc:content-transfer-encoding:message-id:references :to; bh=IF7uDLrw9VNTp1r2QjDGBQQeelyGe9w9koCZmjcGD0Q=; b=FYT4e3GOPvZOBPuODEEddg4kTOkiDmYUr9oZl1MmiMLgK/aBuBqmCF3tCccAqSy6xH d/6KOOeNEzR/wl8jNmk0brXhunfOGsZWd5aVauxDJBWDMI1nE3FO4GNVGov8qDb9Gdm3 QKGPpiXZj7J+a6/fI8QtHotf4W+D1AnW16a8MK8hFhlrUpQuR85YDYa/3mtCkXdY9xut ioKDBUxTJVN2UA5pdyP/hB93Sz+P04qJ0dAh2qY940VOvHMMZlBZSQuzXO4bJiNDpyqo ugNBdjIRJPX/zsJF1h4iVQEkiQl4v5x9eIIWNxFPMhNHE3tMH9w/7HK+prZg7Nr73tqe UE1A== X-Gm-Message-State: ALoCoQnsXKAupeY4PGLzvDLfv3w5Joc2Cz458AWA+QDODm4SuUsLjeAyhyvw1dGADX6/khYlFpuY X-Received: by 10.66.102.72 with SMTP id fm8mr76297882pab.86.1399325636807; Mon, 05 May 2014 14:33:56 -0700 (PDT) Received: from [10.64.26.239] (dc1-prod.netflix.com. [69.53.236.251]) by mx.google.com with ESMTPSA id ff4sm80941357pad.24.2014.05.05.14.33.55 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 05 May 2014 14:33:56 -0700 (PDT) Sender: Warner Losh X-Google-Original-From: Warner Losh Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 7.2 \(1874\)) Subject: Re: svn commit: r265367 - head/lib/libc/regex From: Warner Losh In-Reply-To: <3C7CFFB7-5C84-4AC1-9A81-C718D184E87B@FreeBSD.org> Date: Mon, 5 May 2014 15:33:54 -0600 Content-Transfer-Encoding: quoted-printable Message-Id: <7D7A417E-17C3-4001-8E79-0B57636A70E1@gmail.com> References: <201405051641.s45GfFje086423@svn.freebsd.org> <5367CD77.40909@freebsd.org> <5367EB54.1080109@FreeBSD.org> <3C7CFFB7-5C84-4AC1-9A81-C718D184E87B@FreeBSD.org> To: David Chisnall X-Mailer: Apple Mail (2.1874) Cc: svn-src-head@freebsd.org, svn-src-all@freebsd.org, Pedro Giffuni , Andrey Chernov , src-committers X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 05 May 2014 21:34:03 -0000 On May 5, 2014, at 3:21 PM, David Chisnall wrote: > On 5 May 2014, at 20:49, Pedro Giffuni wrote: >=20 >> Yes, but I reverted it because there are other ways to check for = overflows without the performance hit. >=20 > Do we have a good reusable routine for doing this somewhere? Clang = and gcc both have some idiom recognisers that try to spot when people = are attempting to do this. Clang also has a builtin, which would be = good to use when available. Overflow checking is very cheap on modern = CPUs (add, branch on carry), so it would be nice if we could start = looking for this malloc() and realloc() pattern and replacing the = multiply with something that checks for the error. reallocf(): The reallocf() function is identical to the realloc() function, = except that it will free the passed pointer when the requested memory = cannot be allocated. This is a FreeBSD specific API designed to ease the = problems with traditional coding styles for realloc() causing memory leaks = in libraries. ... The reallocf() function first appeared in FreeBSD 3.0. Warner=