From owner-svn-src-all@FreeBSD.ORG Mon May 5 21:34:03 2014 Return-Path: Delivered-To: svn-src-all@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 8ADBADF8 for ; Mon, 5 May 2014 21:34:03 +0000 (UTC) Received: from mail-pa0-f43.google.com (mail-pa0-f43.google.com [209.85.220.43]) (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 5B40792F for ; Mon, 5 May 2014 21:34:03 +0000 (UTC) Received: by mail-pa0-f43.google.com with SMTP id bj1so3186506pad.2 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=MYfdgDKyQ3Sbms4kTEBrfxId9X0iOnmAgZpG1Ev7sgp+3SFictsMPjIbsQHJoYqBA/ yj0a9rg6b0lINQLZ4FbMb0nEzP37e/By9An2mbXlbXbYfKKHjKW4RlLe9AzZ9NdWHtoO Zto9dOc6GeE0HsdzrNH2U90Y0foGVL9nWD11NNEi7tr1Gueu8wYI/PKgawAImYyNTpDI oKNQHxTRhqqLfg0kdtmCLAKvWOcuYLCcK0vd8b6EpvGlpPqBiyPX75x9T/8MWTzji4VF pJZy5CmFih2p8J+yyayz3mA9yBAV+ZNDGBucDAgOKj5Ffj9H9Ry+ymbWWy6gCnVfWbP9 Kj+w== X-Gm-Message-State: ALoCoQkbLLQL87cYwpGEpjYoxyi8Cjg/Tb8s6lkS1NHkxcNY3EXTyTH3yKJRjAn8GKyu+bmL9nk6 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-all@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" 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=