bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH 2/3] getcwd-lgpl: new module


From: Bruno Haible
Subject: Re: [PATCH 2/3] getcwd-lgpl: new module
Date: Wed, 27 Apr 2011 02:36:03 +0200
User-agent: KMail/1.9.9

Hi Eric,

> My v2 rewrite uses more variables, with better names, to hopefully make
> the logic easier to follow.

Yes, it is easier to follow. Thanks for the improvements.

> I've altered v2 to break the work into 4 phases:
> 
> if (buf) return getcwd()
> if (size) single malloc, getcwd, free buf on error, and return
> using stack, try getcwd, strdup on success
> iterate over larger sizes until we don't have ERANGE failure

Much better!

> > It is good style to not put assignments or other side effects into 'if'
> > conditions:
> > 
> >          buf = realloc (tmp, size);
> >          if (buf == NULL)
> 
> Sure.  After all, it's more lines, but fewer ()

That's not the point. The rationale is that when reading a program, you
often have to ask yourself "where did buf get its last value?". In the
absence of an IDE which tells you this directly, the easiest way is to
look for assignments to 'buf', bottom up. Visual pattern-matching:
search for the regex "^ *buf =". This is why it's useful to have no
assignments inside parentheses and only one assignment per line.

Bruno
-- 
In memoriam Heinrich Conradi <http://de.wikipedia.org/wiki/Heinrich_Conradi>



reply via email to

[Prev in Thread] Current Thread [Next in Thread]