From owner-svn-src-all@FreeBSD.ORG Mon May 5 21:40:12 2014 Return-Path: Delivered-To: svn-src-all@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 BE630476 for ; Mon, 5 May 2014 21:40:12 +0000 (UTC) Received: from mail-lb0-f182.google.com (mail-lb0-f182.google.com [209.85.217.182]) (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 17A6D9A5 for ; Mon, 5 May 2014 21:40:11 +0000 (UTC) Received: by mail-lb0-f182.google.com with SMTP id q8so3193368lbi.41 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=B1TEvKUmSfCDcm2eWuN9nL3GPsw5RNgByoDIq0vDT8WBJd4h1EKaGLS0424I4Oaqne 3l91am755pizqV+TD2V+wMq7iq5sDv4XeshG7TwF/1Qeyv0cE/y7cqQ7pYJJSznpeVfk pCQ5BhUHUJNBBbMNBdArH6AC5OgIL0XpSiO+rtuBnN/KZcOxq2Ti1mwijaem1NcxCebu 2ZWYKi2tmxv6B9x7kpetOgoEsaa2W+VTOUVm1HJW2iSV3ZaJpa09Bny3JMaTzspeOE+f byGxbl/hGYAyy8n8e+qwsnsiI8YiUVIJkwk7Qw4XqfIWTp3Ux9KUk98wEY3K5bXsrVUv zfMw== X-Gm-Message-State: ALoCoQlOyLdcwVtY9sM2cCE6WHu2hOYVWA3zQ8y/p0ZxmXPGB+7Fx07i9A6sfgOyhEjdTYnBwc8P 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-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: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/