Skip to content

Commit

Permalink
container/dictionary: mowgli_dictionary_create(): simplify in other t…
Browse files Browse the repository at this point in the history
…erms

The Clang Static Analyzer identified that much of the code in
mowgli_dictionary_create() was also present in the function beneath it,
mowgli_dictionary_create_named().

Rewrite the former in terms of the latter.

Also fixes a bug where strdup(3) was used instead of mowgli_strdup().
  • Loading branch information
aaronmdjones committed Jan 15, 2019
1 parent 6771599 commit 9243ee0
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions src/libmowgli/container/dictionary.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,7 @@ struct mowgli_dictionary_
mowgli_dictionary_t *
mowgli_dictionary_create(mowgli_dictionary_comparator_func_t compare_cb)
{
mowgli_dictionary_t *dtree = (mowgli_dictionary_t *) mowgli_alloc(sizeof(mowgli_dictionary_t));

dtree->compare_cb = compare_cb;

if (!elem_heap)
elem_heap = mowgli_heap_create(sizeof(mowgli_dictionary_elem_t), 1024, BH_NOW);

return dtree;
return mowgli_dictionary_create_named(NULL, compare_cb);
}

/*
Expand All @@ -86,7 +79,9 @@ mowgli_dictionary_create_named(const char *name, mowgli_dictionary_comparator_fu
mowgli_dictionary_t *dtree = (mowgli_dictionary_t *) mowgli_alloc(sizeof(mowgli_dictionary_t));

dtree->compare_cb = compare_cb;
dtree->id = strdup(name);

if (name && *name)
dtree->id = mowgli_strdup(name);

if (!elem_heap)
elem_heap = mowgli_heap_create(sizeof(mowgli_dictionary_elem_t), 1024, BH_NOW);
Expand Down

0 comments on commit 9243ee0

Please sign in to comment.