Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Ian Collins Newsgroups: comp.lang.c Subject: Re: Memory corruption on freeing a pointer to pointer Date: Tue, 27 Aug 2013 09:16:24 +1200 Lines: 33 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net lNpNel4mbNDDRBc+TiuxaQiuPvc79WuVk3VjOy7L+jjkRCjmfE Cancel-Lock: sha1:HpO8SAwWDGLFCXazv40FPQEBo9g= User-Agent: Mozilla/5.0 (X11; SunOS i86pc; rv:17.0) Gecko/17.0 Thunderbird/17.0 In-Reply-To: Xref: csiph.com comp.lang.c:35881 Ike Naar wrote: > On 2013-08-26, Ian Collins wrote: >> James Kuyper wrote: >>> On 08/26/2013 02:40 AM, Ike Naar wrote: >>>> On 2013-08-25, Keith Thompson wrote: >>>>> James Kuyper writes: >>>>>> On 08/24/2013 03:05 PM, Sharwan Joram wrote: >>>>> [...] >>>>>>> if ( NULL == parameters[parametercount]){ >>>>> >>>>> This is what's known as a "Yoda conndition" >>>>> . I know that a lot of >>>>> programmers like them, and for somewhat valid reasons, but personally I >>>>> find them jarring and unnecessary. Personally, I'd write that as: >>>>> >>>>> if (parameters[parametercount] == NULL) { >>>> >>>> Does it matter? The == operator is symmetric, (X==Y) == (Y==X). >>> >>> Yes, it matters - because it's intended to protect against the typo >>> which replaces == with =, by ensuring that it would cause a constraint >>> violation. The assignment operator is very definitely not symmetric. >> >> The best way to protect against that particular typo is decent unit tests. > > Do not overestimate the value of unit tests. > Let's take, for example, a piece of code that multiplies two > 32-bit numbers to obtain a 64-bit result. What has that got to do with this particular typo? -- Ian Collins