Path: csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: double free Date: Tue, 19 Jul 2016 15:19:09 -0700 Organization: None to speak of Lines: 26 Message-ID: References: <8760sc2aiz.fsf@bsb.me.uk> <57856cf1.441531@news.xs4all.nl> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="945944de09706c9b4e29b53c9d2efdc2"; logging-data="25461"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/5E7Em8OQiUl6aJnOUhVIq" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:ETa3FFkFL2naR2O2IMGIweRt9OM= sha1:tkL6pd1mQYhJVXfn7X7ECN8Kq2E= Xref: csiph.com comp.lang.c:90630 BartC writes: [...] > But anyway, what would worry me about sizeof *p is that it looks like a > pointer dereference of a pointer value that has not yet been initialised. Yes, that's exactly what it is. It's safe because sizeof doesn't evaluate its argument. (Another way that sizeof differs from a function call, and IMHO another reason to write it in a distinctive manner.) Unless the argument is a VLA. If p were an uninitialized object of pointer-to-VLA type, that would be a problem. I've argued elsewhere that it *shouldn't* be, but that's a separate issue, and not something that's terribly likely to happen in practice. I might start a new thread on that. I won't reiterate the advantages of `sizeof *ptr` (or even `sizeof (*ptr)`) over `sizeof (type-that-ptr-points-to)`. [...] -- Keith Thompson (The_Other_Keith) kst-u@mib.org Working, but not speaking, for JetHead Development, Inc. "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"