From owner-svn-src-head@FreeBSD.ORG Mon May 5 21:40:12 2014 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 85ABA473 for ; Mon, 5 May 2014 21:40:12 +0000 (UTC) Received: from mail-lb0-f171.google.com (mail-lb0-f171.google.com [209.85.217.171]) (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 EBC779A4 for ; Mon, 5 May 2014 21:40:11 +0000 (UTC) Received: by mail-lb0-f171.google.com with SMTP id 10so585550lbg.30 for ; Mon, 05 May 2014 14:40:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:message-id:date:from:user-agent:mime-version:to :cc:subject:references:in-reply-to:content-type :content-transfer-encoding; bh=+6DuMZvjek2XrvMOrxkF1HsMDRYyR2h6LYGSFvw/A+E=; b=XcrpR32WGochDOpYSjqXZJTqu1qEu/Vy0chXoFdFNJJBxOmnO0RFlr3Kxkw7qzQA79 2285KAT3CwXJvCw7aWI3HojpH+uqX/dDGAgvj01FDtEwpQ0I0fAJvkPr9j6x5oEhtu7m U6zDOk5ctb8Aau36sBNV0iifT4sNFcjm2UaAONzWqpkpwxOmFuK/3Br2RDwBEjhIIL39 zqaBfzgxEWQ9Ax1dakeOZWViw7I6KiltfMxxbLfrhOBeIMaVKVBy+Sn40rTXG3s+22Fs B4KXwSlpHRCV4i3EzVROydpOPqKtVlfIzSxXNLU/pf5AsL9M8fnaby9ckZ0B98c/h6A6 NIrw== X-Gm-Message-State: ALoCoQlTdcoiTV23KR4bWPCap2ZYwOlvwC7gJ/uHh+JK7PRkR37fDLFa/xfYfkTYLw/gwLD2G3O9 X-Received: by 10.112.106.40 with SMTP id gr8mr27059253lbb.0.1399326003543; Mon, 05 May 2014 14:40:03 -0700 (PDT) Received: from [192.168.1.2] ([89.169.173.68]) by mx.google.com with ESMTPSA id rd5sm10893243lbb.0.2014.05.05.14.40.02 for (version=TLSv1.2 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 05 May 2014 14:40:02 -0700 (PDT) Message-ID: <53680532.7050605@freebsd.org> Date: Tue, 06 May 2014 01:40:02 +0400 From: Andrey Chernov User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.5.0 MIME-Version: 1.0 To: David Chisnall Subject: Re: svn commit: r265367 - head/lib/libc/regex References: <201405051641.s45GfFje086423@svn.freebsd.org> <5367CD77.40909@freebsd.org> In-Reply-To: Content-Type: text/plain; charset=KOI8-R Content-Transfer-Encoding: 7bit Cc: svn-src-head@freebsd.org, svn-src-all@freebsd.org, "Pedro F. Giffuni" , src-committers@freebsd.org 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:40:12 -0000 On 05.05.2014 22:28, David Chisnall wrote: > On 5 May 2014, at 18:42, Andrey Chernov wrote: > >> Please don't commit OpenBSD errors. Now you mix calloc() with the >> realloc() for the same variable later which makes calloc() zeroing >> pointless and waste of CPU. > > The purpose of calloc() here is not (primarily) to get the zero'd size, it's to get the overflow-checking behaviour for calloc. It is better to avoid using undocumented intrinsic knowledge of standard function particular implementation, this is unportable at least and hard to understand too. Moreover, choosing some standard function just due to its arcane side effect is semantically incorrect. If you need bounds checking, you can either making it transparent from the library code point of view (preferred) or use literal visible methods (pragma, online function, etc). > The uses of realloc() later do still potentially overflow, as they follow the realloc(pointer, size * sizeof(type)) antipattern. The code can become completely mess if not follows simple strategies above. -- http://ache.vniz.net/