Revision: 21600
          http://sourceforge.net/p/bibdesk/svn/21600
Author:   hofman
Date:     2017-10-27 16:39:02 +0000 (Fri, 27 Oct 2017)
Log Message:
-----------
check for NULL

Modified Paths:
--------------
    trunk/bibdesk/NSURL_BDSKExtensions.m

Modified: trunk/bibdesk/NSURL_BDSKExtensions.m
===================================================================
--- trunk/bibdesk/NSURL_BDSKExtensions.m        2017-10-27 16:20:05 UTC (rev 
21599)
+++ trunk/bibdesk/NSURL_BDSKExtensions.m        2017-10-27 16:39:02 UTC (rev 
21600)
@@ -72,12 +72,16 @@
 {
     NSCParameterAssert([self isFileURL]);
     
-    CFURLRef fileURL = (CFURLRef)self;
+    CFURLRef fileURL = (CFURLRef)([self isFileReferenceURL] ? [self 
filePathURL] : self);
     FSRef fileRef;
     OSErr err;
     Boolean isFolder, wasAliased;
     CFAllocatorRef allocator = CFGetAllocator(fileURL);
     
+    // this happens for invalid file reference URLs
+    if (fileURL == NULL)
+        return nil;
+    
     // take ownership temporarily, since we use this as a local variable later 
on
     fileURL = CFRetain(fileURL);
     
@@ -95,13 +99,13 @@
         
         if(BDIsEmptyString(lastPathComponent) == FALSE)
             CFArrayAppendValue(strippedComponents, lastPathComponent);
-        if (lastPathComponent) CFRelease(lastPathComponent);
+        CFRelease(lastPathComponent);
         
         oldURL = fileURL;
         NSCParameterAssert(oldURL);
         
         fileURL = CFURLCreateCopyDeletingLastPathComponent(allocator, fileURL);
-        if (oldURL) CFRelease(oldURL);
+        CFRelease(oldURL);
     }
     
     // we now have a valid FSRef, since the last call to CFURLGetFSRef 
succeeded (assuming that / will always work)
@@ -109,8 +113,8 @@
     // remainder of this code assumes that fileURL is non-NULL, which should 
always be true
     NSCParameterAssert(fileURL != NULL);
     
-    // now we have an array of stripped components, and an alias-free URL to 
use as a base
-    // start appending stuff to it again, then resolve the resulting FSRef at 
each step
+    // now we have an array of stripped components, and an alias-free file URL 
to use as a base
+    // start resolving the resulting FSRef at each step, then append 
components when available
     CFIndex idx = CFArrayGetCount(strippedComponents);
     while (1) {
         
@@ -117,7 +121,7 @@
         // use kResolveAliasFileNoUI to avoid blocking while the Finder tries 
to mount idisk or other remote volues; this could be an option
         err = FSResolveAliasFileWithMountFlags(&fileRef, TRUE, &isFolder, 
&wasAliased, kResolveAliasFileNoUI);
         if (err != noErr) {
-            if (fileURL) CFRelease(fileURL);
+            CFRelease(fileURL);
             fileURL = NULL;
             break;
         }
@@ -125,7 +129,7 @@
         // create a new URL based on the resolved FSRef
         oldURL = fileURL;
         fileURL = CFURLCreateFromFSRef(allocator, &fileRef);
-        if (oldURL) CFRelease(oldURL);
+        CFRelease(oldURL);
         
         // if there are no more components, we're done
         if (idx == 0) break;
@@ -135,10 +139,10 @@
 
         oldURL = fileURL;
         fileURL = CFURLCreateCopyAppendingPathComponent(allocator, fileURL, 
CFArrayGetValueAtIndex(strippedComponents, idx), idx > 0);
-        if (oldURL) CFRelease(oldURL);
+        CFRelease(oldURL);
 
         if (CFURLGetFSRef(fileURL, &fileRef) == FALSE) {
-            if (fileURL) CFRelease(fileURL);
+            CFRelease(fileURL);
             fileURL = NULL;
             break;
         }

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Bibdesk-commit mailing list
Bibdesk-commit@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bibdesk-commit

Reply via email to