diff options
author | Michael Drake <tlsa@netsurf-browser.org> | 2016-10-15 16:19:29 +0100 |
---|---|---|
committer | Michael Drake <tlsa@netsurf-browser.org> | 2016-10-15 16:19:29 +0100 |
commit | af1cc1c223bdb7f2337e726268031d3151474561 (patch) | |
tree | d3d8dbad19b1b0b83c0f26c22194e22e337fd0dc /src/select | |
parent | 3b4fdeafdbed6b779b3b826eda9c9b703dd8c0a1 (diff) | |
download | libcss-af1cc1c223bdb7f2337e726268031d3151474561.tar.gz libcss-af1cc1c223bdb7f2337e726268031d3151474561.tar.bz2 |
Selection hash module: calloc instead of malloc, memset.
Diffstat (limited to 'src/select')
-rw-r--r-- | src/select/hash.c | 14 |
1 files changed, 5 insertions, 9 deletions
diff --git a/src/select/hash.c b/src/select/hash.c index 57ab2e5..4807e0f 100644 --- a/src/select/hash.c +++ b/src/select/hash.c @@ -150,42 +150,38 @@ css_error css__selector_hash_create(css_selector_hash **hash) if (hash == NULL) return CSS_BADPARM; - h = malloc(sizeof(css_selector_hash)); + h = calloc(1, sizeof(css_selector_hash)); if (h == NULL) return CSS_NOMEM; /* Element hash */ - h->elements.slots = malloc(DEFAULT_SLOTS * sizeof(hash_entry)); + h->elements.slots = calloc(DEFAULT_SLOTS, sizeof(hash_entry)); if (h->elements.slots == NULL) { free(h); return CSS_NOMEM; } - memset(h->elements.slots, 0, DEFAULT_SLOTS * sizeof(hash_entry)); h->elements.n_slots = DEFAULT_SLOTS; /* Class hash */ - h->classes.slots = malloc(DEFAULT_SLOTS * sizeof(hash_entry)); + h->classes.slots = calloc(DEFAULT_SLOTS, sizeof(hash_entry)); if (h->classes.slots == NULL) { free(h->elements.slots); free(h); return CSS_NOMEM; } - memset(h->classes.slots, 0, DEFAULT_SLOTS * sizeof(hash_entry)); h->classes.n_slots = DEFAULT_SLOTS; /* ID hash */ - h->ids.slots = malloc(DEFAULT_SLOTS * sizeof(hash_entry)); + h->ids.slots = calloc(DEFAULT_SLOTS, sizeof(hash_entry)); if (h->ids.slots == NULL) { free(h->classes.slots); free(h->elements.slots); free(h); return CSS_NOMEM; } - memset(h->ids.slots, 0, DEFAULT_SLOTS * sizeof(hash_entry)); h->ids.n_slots = DEFAULT_SLOTS; - /* Universal chain */ - memset(&h->universal, 0, sizeof(hash_entry)); + /* Universal chain head already initiliased by calloc of `h`. */ h->hash_size = sizeof(css_selector_hash) + DEFAULT_SLOTS * sizeof(hash_entry) + |