'while/else' (ugh) (was Re: [oclug] Ruby)

Matthew Wilcox willy at debian.org
Fri Jun 27 21:41:34 EDT 2003


On Fri, Jun 27, 2003 at 06:45:36PM -0400, Francis J. A. Pinteric wrote:
> On Fri, 27 Jun 2003 21:37:04 +0100
> Matthew Wilcox <willy at debian.org> wrote:
> 
> > if (condition)
> > 	ptr = malloc(1MB);
> > do {
> > 	stuff(ptr);
> > 	condition--;
> > } while (condition);
> > free(ptr);
> >
> 
> This would have a high probability of crashing when you tried to free
> `ptr' if`condition' was false(ie. zero) at the start.

ok, smartypants:

if (!condition)
	return;

ptr = malloc(lots);
do {
	stuff(ptr);
	condition--;
} while (condition);
free(ptr);

-- 
"It's not Hollywood.  War is real, war is primarily not about defeat or
victory, it is about death.  I've seen thousands and thousands of dead bodies.
Do you think I want to have an academic debate on this subject?" -- Robert Fisk



More information about the OCLUG mailing list