summaryrefslogtreecommitdiff
path: root/MobileCydia.mm
diff options
context:
space:
mode:
authorJay Freeman (saurik) <saurik@saurik.com>2011-02-09 13:35:07 -0800
committerJay Freeman (saurik) <saurik@saurik.com>2011-02-12 18:23:15 -0800
commitc65611b940099e8762aa18bd34d75799898e77bd (patch)
treef4e1f3f4858ddd79c58fb688a1e6776915efa82b /MobileCydia.mm
parent2761d5744c0b6e5a8a3d4941f8122a1e8ed95be6 (diff)
Support NULL Cytore return in PackageFind().
Diffstat (limited to 'MobileCydia.mm')
-rw-r--r--MobileCydia.mm26
1 files changed, 20 insertions, 6 deletions
diff --git a/MobileCydia.mm b/MobileCydia.mm
index cc0d978..fe48f96 100644
--- a/MobileCydia.mm
+++ b/MobileCydia.mm
@@ -1427,7 +1427,7 @@ struct MetaValue :
static Cytore::File<MetaValue> MetaFile_;
// }}}
// Cytore Helper Functions {{{
-static PackageValue *PackageFind(const char *name, size_t length) {
+static PackageValue *PackageFind(const char *name, size_t length, bool *fail = NULL) {
SplitHash nhash = { hashlittle(name, length) };
PackageValue *metadata;
@@ -1437,6 +1437,14 @@ static PackageValue *PackageFind(const char *name, size_t length) {
*offset = MetaFile_.New<PackageValue>(length + 1);
metadata = &MetaFile_.Get(*offset);
+ if (metadata == NULL) {
+ if (fail != NULL)
+ *fail = true;
+
+ metadata = new PackageValue();
+ memset(metadata, 0, sizeof(*metadata));
+ }
+
memcpy(metadata->name_, name, length + 1);
metadata->nhash_ = nhash.u16[1];
} else {
@@ -1452,13 +1460,15 @@ static PackageValue *PackageFind(const char *name, size_t length) {
}
static void PackageImport(const void *key, const void *value, void *context) {
+ bool &fail(*reinterpret_cast<bool *>(context));
+
char buffer[1024];
if (!CFStringGetCString((CFStringRef) key, buffer, sizeof(buffer), kCFStringEncodingUTF8)) {
NSLog(@"failed to import package %@", key);
return;
}
- PackageValue *metadata(PackageFind(buffer, strlen(buffer)));
+ PackageValue *metadata(PackageFind(buffer, strlen(buffer), &fail));
NSDictionary *package((NSDictionary *) value);
if (NSNumber *subscribed = [package objectForKey:@"IsSubscribed"])
@@ -9463,11 +9473,15 @@ int main(int argc, char *argv[]) { _pooled
_trace();
if (Packages_ != nil) {
- CFDictionaryApplyFunction((CFDictionaryRef) Packages_, &PackageImport, NULL);
+ bool fail(false);
+ CFDictionaryApplyFunction((CFDictionaryRef) Packages_, &PackageImport, &fail);
_trace();
- [Metadata_ removeObjectForKey:@"Packages"];
- Packages_ = nil;
- Changed_ = true;
+
+ if (!fail) {
+ [Metadata_ removeObjectForKey:@"Packages"];
+ Packages_ = nil;
+ Changed_ = true;
+ }
}
Finishes_ = [NSArray arrayWithObjects:@"return", @"reopen", @"restart", @"reload", @"reboot", nil];