Revision: 3110
          http://skim-app.svn.sourceforge.net/skim-app/?rev=3110&view=rev
Author:   hofman
Date:     2007-10-31 06:13:54 -0700 (Wed, 31 Oct 2007)

Log Message:
-----------
Check return values when using undocumented methods.

Modified Paths:
--------------
    trunk/PDFPage_SKExtensions.m
    trunk/PDFSelection_SKExtensions.m
    trunk/SKPDFView.m

Modified: trunk/PDFPage_SKExtensions.m
===================================================================
--- trunk/PDFPage_SKExtensions.m        2007-10-31 12:39:44 UTC (rev 3109)
+++ trunk/PDFPage_SKExtensions.m        2007-10-31 13:13:54 UTC (rev 3110)
@@ -263,9 +263,9 @@
     
     for (i = 0; i < iMax; i++) {
         NSRange range = [sel safeRangeAtIndex:i onPage:self];
-        unsigned j;
+        unsigned j, jMax = NSMaxRange(range);
         
-        for (j = range.location; j < NSMaxRange(range); j++) {
+        for (j = range.location; j < jMax; j++) {
             if ([indexes containsIndex:j])
                 continue;
             
@@ -276,10 +276,12 @@
             
             for (k = 0; k < kMax; k++) {
                 NSRange selRange = [s safeRangeAtIndex:k onPage:self];
-                [indexes addIndexesInRange:selRange];
-                // due to a bug in PDFKit, the range of the selection can 
sometimes lie partly outside the range of the string
-                if ([string rangeOfCharacterFromSet:[NSCharacterSet 
nonWhitespaceAndNewlineCharacterSet] options:0 
range:NSIntersectionRange(selRange, stringRange)].length)
-                    notEmpty = YES;
+                if (selRange.location != NSNotFound) {
+                    [indexes addIndexesInRange:selRange];
+                    // due to a bug in PDFKit, the range of the selection can 
sometimes lie partly outside the range of the string
+                    if ([string rangeOfCharacterFromSet:[NSCharacterSet 
nonWhitespaceAndNewlineCharacterSet] options:0 
range:NSIntersectionRange(selRange, stringRange)].length)
+                        notEmpty = YES;
+                }
             }
             if (notEmpty)
                 [lines addObject:[NSValue valueWithRect:[s 
boundsForPage:self]]];

Modified: trunk/PDFSelection_SKExtensions.m
===================================================================
--- trunk/PDFSelection_SKExtensions.m   2007-10-31 12:39:44 UTC (rev 3109)
+++ trunk/PDFSelection_SKExtensions.m   2007-10-31 13:13:54 UTC (rev 3110)
@@ -303,7 +303,7 @@
     NSEnumerator *pageEnum = [pages objectEnumerator];
     PDFPage *page;
     while (page = [pageEnum nextObject]) {
-        int i, iMax = [self safeNumberOfRangesOnPage:page];
+        unsigned int i, iMax = [self safeNumberOfRangesOnPage:page];
         for (i = 0; i < iMax; i++) {
             NSRange range = [self safeRangeAtIndex:i onPage:page];
             if (range.length == 0)
@@ -358,9 +358,12 @@
         NSArray *pages = [selection pages];
         PDFPage *firstPage = [pages objectAtIndex:0];
         PDFPage *lastPage = [pages lastObject];
-        int firstIndex = [selection safeRangeAtIndex:0 
onPage:firstPage].location;
-        int lastIndex = NSMaxRange([selection safeRangeAtIndex:[selection 
safeNumberOfRangesOnPage:lastPage] - 1 onPage:lastPage]) - 1;
-        selection = [[firstPage document] selectionFromPage:firstPage 
atCharacterIndex:firstIndex toPage:lastPage atCharacterIndex:lastIndex];
+        
+        unsigned int numRanges = [selection safeNumberOfRangesOnPage:lastPage];
+        unsigned int firstIndex = numRanges ? [selection safeRangeAtIndex:0 
onPage:firstPage].location : NSNotFound;
+        unsigned int lastIndex = numRanges ? NSMaxRange([selection 
safeRangeAtIndex:numRanges - 1 onPage:lastPage]) : NSNotFound;
+        if (firstIndex != NSNotFound && lastIndex != NSNotFound)
+            selection = [[firstPage document] selectionFromPage:firstPage 
atCharacterIndex:firstIndex toPage:lastPage atCharacterIndex:lastIndex - 1];
     }
     return selection ? [selection objectSpecifier] : [NSArray array];
 }
@@ -469,7 +472,7 @@
         PDFSelection *selection = [PDFSelection selectionWithSpecifier:dP 
onPage:page];
         NSArray *pages = [selection pages];
         if ([pages count] && (page = [pages objectAtIndex:last ? [pages count] 
- 1 : 0])) {
-            int count = [selection safeNumberOfRangesOnPage:page];
+            unsigned int count = [selection safeNumberOfRangesOnPage:page];
             if (count > 0) {
                 NSRange range = [selection safeRangeAtIndex:last ? count - 1 : 
0 onPage:page];
                 if (range.length) {

Modified: trunk/SKPDFView.m
===================================================================
--- trunk/SKPDFView.m   2007-10-31 12:39:44 UTC (rev 3109)
+++ trunk/SKPDFView.m   2007-10-31 13:13:54 UTC (rev 3110)
@@ -1425,10 +1425,15 @@
 - (void)checkSpelling:(id)sender {
     PDFSelection *selection = [self currentSelection];
     PDFPage *page = [self currentPage];
-    int index = 0;
+    unsigned int numRanges, index = 0;
     if ([[selection pages] count]) {
         page = [[selection pages] lastObject];
-        index = NSMaxRange([selection safeRangeAtIndex:[selection 
safeNumberOfRangesOnPage:page] - 1 onPage:page]);
+        numRanges = [selection safeNumberOfRangesOnPage:page];
+        if (numRanges > 0) {
+            index = NSMaxRange([selection safeRangeAtIndex:numRanges - 1 
onPage:page]);
+            if (index == NSNotFound)
+                index = 0;
+        }
     }
     [self checkSpellingStartingAtIndex:index onPage:page];
 }
@@ -1436,10 +1441,14 @@
 - (void)showGuessPanel:(id)sender {
     PDFSelection *selection = [self currentSelection];
     PDFPage *page = [self currentPage];
-    int index = 0;
+    unsigned int index = 0;
     if ([[selection pages] count]) {
         page = [[selection pages] objectAtIndex:0];
-        index = [selection safeRangeAtIndex:0 onPage:page].location;
+        if ([selection safeNumberOfRangesOnPage:page] > 0) {
+            index = [selection safeRangeAtIndex:0 onPage:page].location;
+            if (index == NSNotFound)
+                index = 0;
+        }
     }
     [self checkSpellingStartingAtIndex:index onPage:page];
     [[[NSSpellChecker sharedSpellChecker] spellingPanel] orderFront:self];
@@ -3870,9 +3879,9 @@
         unsigned int pageIndex = [self indexForPage:page];
         unsigned int firstPageIndex = [self indexForPage:firstPage];
         unsigned int lastPageIndex = [self indexForPage:lastPage];
-        int n = [selection safeNumberOfRangesOnPage:lastPage];
-        int firstChar = [selection safeRangeAtIndex:0 
onPage:firstPage].location;
-        int lastChar = n ? NSMaxRange([selection safeRangeAtIndex:n - 1 
onPage:lastPage]) - 1 : NSNotFound - 1;
+        unsigned int n = [selection safeNumberOfRangesOnPage:lastPage];
+        unsigned int firstChar = n ? [selection safeRangeAtIndex:0 
onPage:firstPage].location : NSNotFound;
+        unsigned int lastChar = n ? NSMaxRange([selection safeRangeAtIndex:n - 
1 onPage:lastPage]) : NSNotFound;
         NSRect firstRect, lastRect;
         
         if (firstChar != NSNotFound) {
@@ -3881,8 +3890,8 @@
             NSRect bounds = [selection boundsForPage:firstPage];
             firstRect = NSMakeRect(NSMinX(bounds), NSMaxY(bounds) - 10.0, 5.0, 
10.0);
         }
-        if (lastChar != NSNotFound - 1) {
-            lastRect = [lastPage characterBoundsAtIndex:lastChar];
+        if (lastChar != NSNotFound && lastChar != 0) {
+            lastRect = [lastPage characterBoundsAtIndex:lastChar - 1];
         } else {
             NSRect bounds = [selection boundsForPage:lastPage];
             lastRect = NSMakeRect(NSMaxX(bounds) - 5.0, NSMinY(bounds), 5.0, 
10.0);


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

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit

Reply via email to