aboutsummaryrefslogtreecommitdiff
path: root/ewah/bitmap.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2016-02-22 17:45:15 -0500
committerJunio C Hamano <gitster@pobox.com>2016-02-22 14:51:09 -0800
commit08c95df8faa25ab4c9ad3da45bc12abb9274d343 (patch)
tree6f238edb11041a0383ce970b19963c90feaf4db7 /ewah/bitmap.c
parentfb7dbf3e7a668ab60c158d3d1efc77578ef9db1b (diff)
downloadgit-08c95df8faa25ab4c9ad3da45bc12abb9274d343.tar.gz
git-08c95df8faa25ab4c9ad3da45bc12abb9274d343.tar.xz
ewah: convert to REALLOC_ARRAY, etc
Now that we're built around xmalloc and friends, we can use helpers like REALLOC_ARRAY, ALLOC_GROW, and so on to make the code shorter and protect against integer overflow. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'ewah/bitmap.c')
-rw-r--r--ewah/bitmap.c16
1 files changed, 4 insertions, 12 deletions
diff --git a/ewah/bitmap.c b/ewah/bitmap.c
index c88daa0aa..7103ceefb 100644
--- a/ewah/bitmap.c
+++ b/ewah/bitmap.c
@@ -17,7 +17,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-#include "git-compat-util.h"
+#include "cache.h"
#include "ewok.h"
#define EWAH_MASK(x) ((eword_t)1 << (x % BITS_IN_EWORD))
@@ -38,9 +38,7 @@ void bitmap_set(struct bitmap *self, size_t pos)
if (block >= self->word_alloc) {
size_t old_size = self->word_alloc;
self->word_alloc = block * 2;
- self->words = xrealloc(self->words,
- self->word_alloc * sizeof(eword_t));
-
+ REALLOC_ARRAY(self->words, self->word_alloc);
memset(self->words + old_size, 0x0,
(self->word_alloc - old_size) * sizeof(eword_t));
}
@@ -100,12 +98,7 @@ struct bitmap *ewah_to_bitmap(struct ewah_bitmap *ewah)
ewah_iterator_init(&it, ewah);
while (ewah_iterator_next(&blowup, &it)) {
- if (i >= bitmap->word_alloc) {
- bitmap->word_alloc *= 1.5;
- bitmap->words = xrealloc(
- bitmap->words, bitmap->word_alloc * sizeof(eword_t));
- }
-
+ ALLOC_GROW(bitmap->words, i + 1, bitmap->word_alloc);
bitmap->words[i++] = blowup;
}
@@ -134,8 +127,7 @@ void bitmap_or_ewah(struct bitmap *self, struct ewah_bitmap *other)
if (self->word_alloc < other_final) {
self->word_alloc = other_final;
- self->words = xrealloc(self->words,
- self->word_alloc * sizeof(eword_t));
+ REALLOC_ARRAY(self->words, self->word_alloc);
memset(self->words + original_size, 0x0,
(self->word_alloc - original_size) * sizeof(eword_t));
}