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

Incorrect objectForKey results for keys not in table. #8

Closed
omarkilani opened this issue Mar 11, 2011 · 2 comments
Closed

Incorrect objectForKey results for keys not in table. #8

omarkilani opened this issue Mar 11, 2011 · 2 comments
Assignees

Comments

@omarkilani
Copy link

Hi John,

There's a bug in _JKDictionaryHashTableEntryForKey which returns an incorrect result (returns an object when it should return NULL) if the key falls into the same bucket as another key, but the hash and value don't match.

The loop does:

atEntry = &dictionary->entry[(keyEntry + idx) % dictionary->capacity];

But never clears atEntry if we get to the end of the loop and the key wasn't found.

Thanks!

Regards,
Omar

@johnezang
Copy link
Owner

This was reported by another user, but I never heard back if the fix I gave them worked. I've checked in that fix.

If you happen to have some JSON that tickles this bug, could you paste it in to the ticket? This condition never showed up during my testing, it requires just the right set of conditions that's almost impossible to create by hand.

@omarkilani
Copy link
Author

The JSON:

{"l1":1,"l2":2,"l3":3}

Will reproduce this issue, and return the value for 'l2' if you request the value for 'l4'.

Sample code:

#import <Foundation/Foundation.h>
#import "JSONKit.h"

int main(int argc, char *argv[]) {
  NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  NSDictionary *dict = [@"{\"l1\":1,\"l2\":2,\"l3\":3}" objectFromJSONString];
  NSLog(@"dict = %@", dict);
  NSLog(@"objectForKey:l4 = %@", [dict objectForKey:@"l4"]);
  [pool release];
  return(0);
}

Sample output:

2011-03-12 14:10:42.352 main[45328:903] dict = {
    l1 = 1;
    l2 = 2;
    l3 = 3;
}
2011-03-12 14:10:42.355 main[45328:903] objectForKey:l4 = 2

Hope this helps!

@ghost ghost assigned johnezang May 21, 2011
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants