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

Going through your dict file #18

Open
janus opened this issue Feb 16, 2014 · 2 comments
Open

Going through your dict file #18

janus opened this issue Feb 16, 2014 · 2 comments

Comments

@janus
Copy link

janus commented Feb 16, 2014

dictIterator _dictGetIterator(dict *d)
{
dictIterator *iter = malloc(sizeof(_iter));

iter->d = d;
iter->table = 0;
iter->index = -1;
iter->safe = 0;
iter->entry = NULL;
iter->nextEntry = NULL;
return iter;

}

No check to see if malloc actually creates heap object.

dictEntry *dictNext(dictIterator *iter)
{
while (1) {
if (iter->entry == NULL) {
dictht *ht = &iter->d->ht[iter->table];
if (iter->safe && iter->index == -1 && iter->table == 0)
iter->d->iterators++;
iter->index++;
if (iter->index >= (signed) ht->size) {
if (dictIsRehashing(iter->d) && iter->table == 0) {
iter->table++;
iter->index = 0;
ht = &iter->d->ht[1];
} else {
break;
}

Looks like this code would break someday because of inconsistency,&iter->d->ht[iter->table] and &iter->d->ht[1]

@fizx
Copy link
Owner

fizx commented Feb 17, 2014

First off, thanks for the comments! I really appreciate you taking a look. This dict implementation is taken straight from Redis, so it might be better to raise questions upstream. I'm open to fixing obvious things, though.

@janus
Copy link
Author

janus commented Feb 17, 2014

Just trying to learn C by reading others' code. And lately I was trying to
understand how web server works, and your code seems to be pretty easy to
follow. However, I found a couple of things two hard to understand. I would
need help to get through them

On Mon, Feb 17, 2014 at 3:14 AM, Kyle Maxwell notifications@github.comwrote:

First off, thanks for the comments! I really appreciate you taking a look.
This dict implementation is taken straight from Redis, so it might be
better to raise questions upstream. I'm open to fixing obvious things,
though.

Reply to this email directly or view it on GitHubhttps://github.com//issues/18#issuecomment-35223997
.

Satajanus Nig. Ltd

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

No branches or pull requests

2 participants