summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Drake <tlsa@netsurf-browser.org>2016-10-15 16:19:29 +0100
committerMichael Drake <tlsa@netsurf-browser.org>2016-10-15 16:19:29 +0100
commitaf1cc1c223bdb7f2337e726268031d3151474561 (patch)
treed3d8dbad19b1b0b83c0f26c22194e22e337fd0dc
parent3b4fdeafdbed6b779b3b826eda9c9b703dd8c0a1 (diff)
downloadlibcss-af1cc1c223bdb7f2337e726268031d3151474561.tar.gz
libcss-af1cc1c223bdb7f2337e726268031d3151474561.tar.bz2
Selection hash module: calloc instead of malloc, memset.
-rw-r--r--src/select/hash.c14
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) +