Erroneous use of getcwd on lib/nspath.c

Andreas Ericsson ae at op5.se
Fri Oct 26 18:06:52 CEST 2012


On 10/26/2012 03:12 PM, Ricardo Jose Maraschini wrote:
> 
> Accordingly to manpages and some home made tests, getcwd returns NULL
> when an error occurs, not a value < 0.
> 

Ah, right. Good catch.

> Following, on openbsd MAX_PATH is 1024 bytes while in linux it is 4096
> bytes, so i thought it would be ok to include <limits.h> and use macro
> MAX_PATH, not a fixed size of 4096.
> 

I think you mean PATH_MAX. 4096 is the upper limit, so we'll be fine
using that (except for truly pathological cases where someone may
use a system where PATH_MAX is larger).

> Also we don't need to make sizeof(path) - 1 when calling getcwd.
> Quoting manpage:
> 
> "The size argument is the size, in bytes, of the array referenced by
> buf."
> 

We need an extra byte to spare for a nul byte in case the system we're
on doesn't leave any room for it in its getcwd() implementation (AIX,
for instance).

> Is it sounds resonable?

Sort of, but it's not important and the current code works just fine
as it is, so I'll drop this patch for now, apart from the return
code check thing.

Thanks.

-- 
Andreas Ericsson                   andreas.ericsson at op5.se
OP5 AB                             www.op5.se
Tel: +46 8-230225                  Fax: +46 8-230231

Considering the successes of the wars on alcohol, poverty, drugs and
terror, I think we should give some serious thought to declaring war
on peace.

------------------------------------------------------------------------------
The Windows 8 Center 
In partnership with Sourceforge
Your idea - your app - 30 days. Get started!
http://windows8center.sourceforge.net/
what-html-developers-need-to-know-about-coding-windows-8-metro-style-apps/




More information about the Developers mailing list