Date: Tue, 06 May 2014 01:40:02 +0400 From: Andrey Chernov <ache@freebsd.org> To: David Chisnall <theraven@FreeBSD.org> Cc: svn-src-head@freebsd.org, svn-src-all@freebsd.org, "Pedro F. Giffuni" <pfg@FreeBSD.org>, src-committers@freebsd.org Subject: Re: svn commit: r265367 - head/lib/libc/regex Message-ID: <53680532.7050605@freebsd.org> In-Reply-To: <B11B5B25-8E05-4225-93D5-3A607332F19A@FreeBSD.org> References: <201405051641.s45GfFje086423@svn.freebsd.org> <5367CD77.40909@freebsd.org> <B11B5B25-8E05-4225-93D5-3A607332F19A@FreeBSD.org>
next in thread | previous in thread | raw e-mail | index | archive | help
On 05.05.2014 22:28, David Chisnall wrote: > On 5 May 2014, at 18:42, Andrey Chernov <ache@freebsd.org> 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/
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?53680532.7050605>