diff options
author | Jim Meyering <meyering@redhat.com> | 2008-01-02 22:09:13 +0100 |
---|---|---|
committer | Jim Meyering <meyering@redhat.com> | 2008-01-14 17:58:38 +0100 |
commit | f35f3801856404c5642508cc4d57c4a31de37258 (patch) | |
tree | 27886246183b5b47eae1bdd6b9fb7065400af5e5 | |
parent | 548312ccada6ded86ad1c4217eebcbcfc9065a6a (diff) | |
download | idutils-f35f3801856404c5642508cc4d57c4a31de37258.tar.gz idutils-f35f3801856404c5642508cc4d57c4a31de37258.tar.bz2 idutils-f35f3801856404c5642508cc4d57c4a31de37258.zip |
Replace uses of xrealloc with uses of safer variants.
* src/mkid.c (write_id_file): Avoid risk of overflow.
(make_sibling_summary, add_token_to_summary): Likewise.
Signed-off-by: Jim Meyering <meyering@redhat.com>
-rw-r--r-- | src/mkid.c | 18 |
1 files changed, 11 insertions, 7 deletions
@@ -580,8 +580,10 @@ write_id_file (struct idhead *idhp) if (verbose_flag) printf (_("Sorting tokens...\n")); + assert (summary_root->sum_hits_count == token_table.ht_fill); - tokens = xrealloc (summary_root->sum_tokens, sizeof(struct token *) * token_table.ht_fill); + tokens = xnrealloc (summary_root->sum_tokens, + token_table.ht_fill, sizeof *tokens); qsort (tokens, token_table.ht_fill, sizeof (struct token *), token_qsort_cmp); if (verbose_flag) @@ -781,12 +783,13 @@ struct summary * make_sibling_summary (struct summary *summary) { struct summary *parent = summary->sum_parent; - unsigned long size; + size_t size; if (parent == NULL) { levels++; - summary_root = summary->sum_parent = parent = xcalloc (1, sizeof(struct summary)); + summary_root = summary->sum_parent = parent + = xcalloc (1, sizeof(struct summary)); parent->sum_level = levels; parent->sum_kids[0] = summary; parent->sum_hits_count = summary->sum_hits_count; @@ -800,7 +803,8 @@ make_sibling_summary (struct summary *summary) else { parent->sum_tokens_size = size; - parent->sum_tokens = xrealloc (summary->sum_tokens, sizeof(struct token *) * size); + parent->sum_tokens = xnrealloc (summary->sum_tokens, size, + sizeof *summary->sum_tokens); } summary->sum_tokens = 0; } @@ -928,12 +932,12 @@ sign_token (struct token *token) void add_token_to_summary (struct summary *summary, struct token *token) { - unsigned long size = summary->sum_tokens_size; + size_t size = summary->sum_tokens_size; if (summary->sum_hits_count >= size) { - size *= 2; - summary->sum_tokens = xrealloc (summary->sum_tokens, sizeof(struct token *) * size); + summary->sum_tokens = x2nrealloc (summary->sum_tokens, &size, + sizeof *summary->sum_tokens); summary->sum_tokens_size = size; } summary->sum_tokens[summary->sum_hits_count++] = token; |