From 74b265652291a28f2ffdfd120e5284ca974cc87c Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Wed, 5 Mar 2008 05:28:38 +0000 Subject: [PATCH] Handle the case of a package with a NULL section. --- Cydia.mm | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/Cydia.mm b/Cydia.mm index d2211780..c643b34c 100644 --- a/Cydia.mm +++ b/Cydia.mm @@ -1067,7 +1067,8 @@ NSString *Scour(const char *field, const char *begin, const char *end) { } - (NSString *) section { - return [[NSString stringWithCString:iterator_.Section()] stringByReplacingCharacter:'_' withCharacter:' ']; + const char *section = iterator_.Section(); + return section == NULL ? nil : [[NSString stringWithCString:section] stringByReplacingCharacter:'_' withCharacter:' ']; } - (Address *) maintainer { @@ -1178,9 +1179,19 @@ NSString *Scour(const char *field, const char *begin, const char *end) { } - (NSComparisonResult) compareBySectionAndName:(Package *)package { - NSComparisonResult result = [[self section] compare:[package section]]; - if (result != NSOrderedSame) - return result; + NSString *lhs = [self section]; + NSString *rhs = [package section]; + + if (lhs == NULL && rhs != NULL) + return NSOrderedAscending; + else if (lhs != NULL && rhs == NULL) + return NSOrderedDescending; + else if (lhs != NULL && rhs != NULL) { + NSComparisonResult result = [lhs compare:rhs]; + if (result != NSOrderedSame) + return result; + } + return [self compareByName:package]; } @@ -1387,10 +1398,11 @@ NSString *Scour(const char *field, const char *begin, const char *end) { [cell setValue:(installed == nil ? @"n/a" : installed)]; } break; - case 2: + case 2: { [cell setTitle:@"Section"]; - [cell setValue:[package_ section]]; - break; + NSString *section([package_ section]); + [cell setValue:(section == nil ? @"n/a" : section)]; + } break; case 3: [cell setTitle:@"Expanded Size"]; @@ -2329,7 +2341,8 @@ NSString *Scour(const char *field, const char *begin, const char *end) { [name_ setText:@"All Packages"]; [count_ setText:nil]; } else { - [name_ setText:[section name]]; + NSString *name = [section name]; + [name_ setText:(name == nil ? @"(No Section)" : name)]; [count_ setText:[NSString stringWithFormat:@"%d", [section count]]]; } } @@ -2544,10 +2557,10 @@ NSString *Scour(const char *field, const char *begin, const char *end) { Package *package = [packages_ objectAtIndex:offset]; NSString *name = [package section]; - if (section == nil || ![[section name] isEqual:name]) { + if (section == nil || name != nil && ![[section name] isEqual:name]) { section = [[[Section alloc] initWithName:name row:offset] autorelease]; - if ([name isEqualToString:section_]) + if (name == nil || [name isEqualToString:section_]) nsection = section; [sections addObject:section]; } -- 2.45.2