Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Lawrence D'Oliveiro Newsgroups: comp.lang.c Subject: Re: Fixing a sample from K&R book using cake static analyser Date: Sun, 23 Jun 2024 23:50:33 -0000 (UTC) Organization: A noiseless patient Spider Lines: 30 Message-ID: References: <20240623022343.ec355c69a3d9eb03ad4a50f2@gmail.moc> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Injection-Date: Mon, 24 Jun 2024 01:50:33 +0200 (CEST) Injection-Info: dont-email.me; posting-host="3048fea01d51f9337586ac8e02824e6c"; logging-data="612995"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1930gy2cRORr9jQ/S6t3s3a" User-Agent: Pan/0.158 (Avdiivka; ) Cancel-Lock: sha1:eHg7yKxw1d3J71AUNPOVR2afTas= Bytes: 1934 On Sun, 23 Jun 2024 00:53:04 +0100, bart wrote: > On 23/06/2024 00:30, Lawrence D'Oliveiro wrote: > >> On Sun, 23 Jun 2024 02:23:43 +0300, Anton Shepelev wrote: >> >>> Why are you so afraid of `goto' ... >> >> Look up the concept of a “Nassi-Shneiderman diagram”. It allows >> arbitrary nesting of complex code, with dynamic allocation going on, >> while minimizing flow-control headaches. Another point is idempotency of disposal routines. By which I mean that attempting to free a NULL pointer is a harmless no-op. How many times have you seen pointless rigmarole like if (p1) free(p1); if (p2) free(p2); if (p3) free(p3); when it could be written so much more simply as free(p1); free(p2); free(p3); You’ll notice that my np_free routine can be used in the same way.