Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add nil checks for #462 and #459 #463

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions YapDatabase/Extensions/AutoView/YapDatabaseAutoViewTransaction.m
Original file line number Diff line number Diff line change
Expand Up @@ -555,10 +555,14 @@ - (void)insertRowid:(int64_t)rowid
[databaseTransaction getCollectionKey:&another
object:&anotherObject
forRowid:anotherRowid];

return sortingBlock(databaseTransaction, group,
collectionKey.collection, collectionKey.key, object,
another.collection, another.key, anotherObject);

if (object && anotherObject) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation seems off in all these changes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops

return sortingBlock(databaseTransaction, group,
collectionKey.collection, collectionKey.key, object,
another.collection, another.key, anotherObject);
} else {
return NSOrderedAscending;
}
}
else if (sorting->blockType == YapDatabaseBlockTypeWithMetadata)
{
Expand Down Expand Up @@ -588,9 +592,13 @@ - (void)insertRowid:(int64_t)rowid
metadata:&anotherMetadata
forRowid:anotherRowid];

return sortingBlock(databaseTransaction, group,
collectionKey.collection, collectionKey.key, object, metadata,
another.collection, another.key, anotherObject, anotherMetadata);
if (object && anotherObject) {
return sortingBlock(databaseTransaction, group,
collectionKey.collection, collectionKey.key, object, metadata,
another.collection, another.key, anotherObject, anotherMetadata);
} else {
return NSOrderedAscending;
}
}

#pragma clang diagnostic pop
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1158,7 +1158,9 @@ - (BOOL)enumerateKeysAndObjectsMatchingQuery:(YapDatabaseQuery *)query
id object = nil;
[self->databaseTransaction getCollectionKey:&ck object:&object forRowid:rowid];

block(ck.collection, ck.key, object, stop);
if (ck && object) {
block(ck.collection, ck.key, object, stop);
}
}];

return result;
Expand All @@ -1178,7 +1180,9 @@ - (BOOL)enumerateRowsMatchingQuery:(YapDatabaseQuery *)query
id metadata = nil;
[self->databaseTransaction getCollectionKey:&ck object:&object metadata:&metadata forRowid:rowid];

block(ck.collection, ck.key, object, metadata, stop);
if (ck && object) {
block(ck.collection, ck.key, object, metadata, stop);
}
}];

return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1287,7 +1287,9 @@ - (BOOL)enumerateKeysAndObjectsMatchingQuery:(YapDatabaseQuery *)query
id object = nil;
[self->databaseTransaction getCollectionKey:&ck object:&object forRowid:rowid];

block(ck.collection, ck.key, object, stop);
if (ck && object) {
block(ck.collection, ck.key, object, stop);
}
}];

return result;
Expand Down
7 changes: 7 additions & 0 deletions YapDatabase/Extensions/View/YapDatabaseViewTransaction.m
Original file line number Diff line number Diff line change
Expand Up @@ -1308,6 +1308,13 @@ - (void)insertRowid:(int64_t)rowid collectionKey:(YapCollectionKey *)collectionK

NSString *pageKey = pageMetadata->pageKey;
YapDatabaseViewPage *page = [self pageForPageKey:pageKey];

NSAssert(page != nil, @"Missing page in group(%@)", group);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any idea what can lead to this?

FWIW we've seen similar crashes, but haven't root-caused it.

Hopefully this assert/logging will help track it down...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure, I've never caught it live, only from crash logs


if (!page) {
YDBLogError(@"Missing page in group(%@)! Error inserting key(%@) collection(%@) in group(%@) at index(%lu) with page(%@) pageOffset(%lu)", group);
return;
}

YDBLogVerbose(@"Inserting key(%@) collection(%@) in group(%@) at index(%lu) with page(%@) pageOffset(%lu)",
collectionKey.key, collectionKey.collection, group,
Expand Down
28 changes: 21 additions & 7 deletions YapDatabase/YapDatabaseTransaction.m
Original file line number Diff line number Diff line change
Expand Up @@ -2634,7 +2634,9 @@ - (void)enumerateRowsForKeys:(NSArray *)keys
[connection->metadataCache setObject:[YapNull null] forKey:cacheKey];
}

block(keyIndex, object, metadata, &stop);
if (object) {
block(keyIndex, object, metadata, &stop);
}

[keyIndexDict removeObjectForKey:key];

Expand Down Expand Up @@ -2963,7 +2965,9 @@ - (void)_enumerateKeysAndObjectsInCollection:(NSString *)collection
}
}

block(rowid, key, object, &stop);
if (object) {
block(rowid, key, object, &stop);
}

if (stop || mutation.isMutated) break;
}
Expand Down Expand Up @@ -3077,7 +3081,9 @@ - (void)_enumerateKeysAndObjectsInCollections:(NSArray *)collections
}
}

block(rowid, collection, key, object, &stop);
if (object) {
block(rowid, collection, key, object, &stop);
}

if (stop || mutation.isMutated) break;
}
Expand Down Expand Up @@ -3193,7 +3199,9 @@ - (void)_enumerateKeysAndObjectsInAllCollectionsUsingBlock:
}
}

block(rowid, collection, key, object, &stop);
if (object) {
block(rowid, collection, key, object, &stop);
}

if (stop || mutation.isMutated) break;
}
Expand Down Expand Up @@ -3729,7 +3737,9 @@ - (void)_enumerateRowsInCollection:(NSString *)collection
}
}

block(rowid, key, object, metadata, &stop);
if (object) {
block(rowid, key, object, metadata, &stop);
}

if (stop || mutation.isMutated) break;
}
Expand Down Expand Up @@ -3882,7 +3892,9 @@ - (void)_enumerateRowsInCollections:(NSArray *)collections
}
}

block(rowid, collection, key, object, metadata, &stop);
if (object) {
block(rowid, collection, key, object, metadata, &stop);
}

if (stop || mutation.isMutated) break;
}
Expand Down Expand Up @@ -4027,7 +4039,9 @@ - (void)_enumerateRowsInAllCollectionsUsingBlock:
}
}

block(rowid, collection, key, object, metadata, &stop);
if (object) {
block(rowid, collection, key, object, metadata, &stop);
}

if (stop || mutation.isMutated) break;
}
Expand Down