aboutsummaryrefslogtreecommitdiffstats
path: root/st.c
diff options
context:
space:
mode:
authorPeter Zhu <peter@peterzhu.ca>2023-06-29 16:31:35 -0400
committerPeter Zhu <peter@peterzhu.ca>2023-06-30 09:13:31 -0400
commit58386814a7c7275f66ffa111175fca2fe307a1b5 (patch)
tree56bfd1daec3a6d83dfda64b569de1b9fbbb4d23c /st.c
parent37a893d12915b8860f6880d6a0c2859e096ab4ff (diff)
downloadruby-58386814a7c7275f66ffa111175fca2fe307a1b5.tar.gz
Don't check for null pointer in calls to free
According to the C99 specification section 7.20.3.2 paragraph 2: > If ptr is a null pointer, no action occurs. So we do not need to check that the pointer is a null pointer.
Diffstat (limited to 'st.c')
-rw-r--r--st.c20
1 files changed, 8 insertions, 12 deletions
diff --git a/st.c b/st.c
index 119a6964b4..755e230c9a 100644
--- a/st.c
+++ b/st.c
@@ -657,8 +657,7 @@ st_clear(st_table *tab)
void
st_free_table(st_table *tab)
{
- if (tab->bins != NULL)
- free(tab->bins);
+ free(tab->bins);
free(tab->entries);
free(tab);
}
@@ -777,8 +776,7 @@ rebuild_table(st_table *tab)
tab->entry_power = new_tab->entry_power;
tab->bin_power = new_tab->bin_power;
tab->size_ind = new_tab->size_ind;
- if (tab->bins != NULL)
- free(tab->bins);
+ free(tab->bins);
tab->bins = new_tab->bins;
free(tab->entries);
tab->entries = new_tab->entries;
@@ -2090,10 +2088,8 @@ st_expand_table(st_table *tab, st_index_t siz)
n = get_allocated_entries(tab);
MEMCPY(tmp->entries, tab->entries, st_table_entry, n);
free(tab->entries);
- if (tab->bins != NULL)
- free(tab->bins);
- if (tmp->bins != NULL)
- free(tmp->bins);
+ free(tab->bins);
+ free(tmp->bins);
tab->entry_power = tmp->entry_power;
tab->bin_power = tmp->bin_power;
tab->size_ind = tmp->size_ind;
@@ -2111,10 +2107,10 @@ st_rehash_linear(st_table *tab)
int eq_p, rebuilt_p;
st_index_t i, j;
st_table_entry *p, *q;
- if (tab->bins) {
- free(tab->bins);
- tab->bins = NULL;
- }
+
+ free(tab->bins);
+ tab->bins = NULL;
+
for (i = tab->entries_start; i < tab->entries_bound; i++) {
p = &tab->entries[i];
if (DELETED_ENTRY_P(p))