[Top][All Lists]

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

Re: -[NSFileManager fileSystemRepresentationWithPath:] not error safe -

From: Richard Frith-Macdonald
Subject: Re: -[NSFileManager fileSystemRepresentationWithPath:] not error safe - will crash on argument=nil
Date: Mon, 16 Sep 2002 15:25:49 +0100

On Monday, September 16, 2002, at 10:53 AM, Roland Schwingel wrote:


While migrating sources I found that fileSystemRepresentationWithPath: can not correctly handle arguments equal to nil so it will crash on win. (I am using base-1.5.0)
This method is quite frequently used in NSFileManager on many locations.

- (const char*) fileSystemRepresentationWithPath: (NSString*)path
#ifdef __MINGW__
  * If path is in Unix format, transmogrify it so Windows functions
  * can handle it
  */   NSString    *newpath;
 const char    *c_path;
 int        l;

 path = [path stringByStandardizingPath];
 newpath = path;
 c_path = [path cString];
 l = strlen(c_path);

 if (c_path == 0)
     return 0;

If you supply nil for path it will crash in strlen() which is quite ugly.
I suggest to move
 l = strlen(c_path);

after the following if (c_path == 0) statement. So the method will correctly exit in this case.
(and bringing back OS4.2 behaviour).

What do you think? Is this change acceptable?

Done ... thanks.

reply via email to

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