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: Sat, 09 Jul 2016 14:10:03 -0700 Organization: None to speak of Lines: 23 Message-ID: References: <577ba42f.13700328@news.xs4all.nl> <48c43c3f-8e7e-0509-5b9d-04133e7bb537@verizon.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="945944de09706c9b4e29b53c9d2efdc2"; logging-data="16224"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/uzrejgIykKu1UvYUH5DYm" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:HtP7ac70c/YATbxfGlKrdrxbxHM= sha1:kXEZAAE5Z/7L8tSxnRTNTnpvAFA= Xref: csiph.com comp.lang.c:90159 jameskuyper@verizon.net writes: [...] > That's actually a disadvantage. It means that the cast needs to be > changed whenever the type of p changes, in order to avoid the error > message, a problem that can be removed if you remove the cast. Note, > in particular, that fixing only the cast does NOT fix the real > problem: > > p = (double*) malloc( sizeof(int)); > > and the cast causes an utterly unnecessary and useless error message > if you add it to what is otherwise the preferred way of handling the > call: > > p = (double*) malloc( sizeof *p); I presume you didn't intend to use a cast there. -- 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"