Skip to content
This repository has been archived by the owner on Aug 31, 2018. It is now read-only.

BAD ACCESS in enumerateFromIndex:to:block: #10

Open
scriptease opened this issue Oct 27, 2012 · 1 comment
Open

BAD ACCESS in enumerateFromIndex:to:block: #10

scriptease opened this issue Oct 27, 2012 · 1 comment

Comments

@scriptease
Copy link

Hi,

i get a bad access when i am using enumerateFromIndex, normal access with storedDataForIndexKey works.

Here the stack trace:

#0  0x017bfeff in memcpy$VARIANT$sse42 ()
#1  0x0016666b in std::string::append(char const*, unsigned long) ()
#2  0x000448c8 in leveldb::AppendInternalKey(std::string*, leveldb::ParsedInternalKey const&) at /Users/florian/GitHub/NULevelDB/leveldb/db/dbformat.cc:19
#3  0x0002e466 in leveldb::(anonymous namespace)::DBIter::Seek(leveldb::Slice const&) at /Users/florian/GitHub/NULevelDB/leveldb/db/db_iter.cc:260
#4  0x0001a813 in NULDBIterateIndex(leveldb::DB*, leveldb::Slice&, leveldb::Slice&, signed char ()(unsigned long long, NSData*) block_pointer) at /Users/florian/GitHub/NULevelDB/Classes/NULDBDB+Enumeration.mm:111
#5  0x00019c07 in -[NULDBDB(Enumeration) enumerateFromIndex:to:block:] at /Users/florian/GitHub/NULevelDB/Classes/NULDBDB+Enumeration.mm:186
#6  0x00002cda in -[NULevelDB_TestAppAppDelegate runTests] at     /Users/florian/GitHub/NULevelDB/Tests/NULevelDB-TestApp/NULevelDB-TestApp/NULevelDB_TestAppAppDelegate.m:90

Here a simple example that will crash

NSData* data = [NSData dataWithContentsOfFile:@"~/GitHub/NULevelDB/README.md"];

[db storeData: data forIndexKey:10 error:NULL];
[db storeData: data forIndexKey:11 error:NULL];
[db storeData: data forIndexKey:12 error:NULL];
[db storeData: data forIndexKey:13 error:NULL];
[db storeData: data forIndexKey:14 error:NULL];
[db storeData: data forIndexKey:15 error:NULL];

NSLog(@"%@",[db storedDataForIndexKey:10 error:NULL]);

[db enumerateFromIndex:10 to:15 block:^(uint64_t key, NSData *value) {
    NSLog(@"%@",value);
    return YES;
}];

Thanks!

Greetings,
Florian

@scriptease
Copy link
Author

Found the bug in NULDBDB+Enumeration:

- (void)enumerateFromIndex:(uint64_t)start to:(uint64_t)limit block:(BOOL (^)(uint64_t key, NSData *value))block {
    Slice startSlice((char *)start, sizeof(uint64_t));
    Slice limitSlice((char *)limit, sizeof(uint64_t));

    NULDBIterateIndex(db, startSlice, limitSlice, block);
}

should be

- (void)enumerateFromIndex:(uint64_t)start to:(uint64_t)limit block:(BOOL (^)(uint64_t key, NSData *value))block {
    Slice startSlice((char *)&start, sizeof(uint64_t));
    Slice limitSlice((char *)&limit, sizeof(uint64_t));

    NULDBIterateIndex(db, startSlice, limitSlice, block);
}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant