diff options
author | Markus Armbruster <armbru@redhat.com> | 2014-08-19 10:31:09 +0200 |
---|---|---|
committer | Kevin Wolf <kwolf@redhat.com> | 2014-08-20 11:51:28 +0200 |
commit | 02c4f26b1517d9e403ec10d6f6ca3c0276d19e43 (patch) | |
tree | 72ab6699d8ce12001632bf30fe4bcd801678465b /block/bochs.c | |
parent | 5839e53bbc0fec56021d758aab7610df421ed8c8 (diff) |
block: Use g_new() & friends to avoid multiplying sizes
g_new(T, n) is safer than g_malloc(sizeof(*v) * n) for two reasons.
One, it catches multiplication overflowing size_t. Two, it returns
T * rather than void *, which lets the compiler catch more type
errors.
Perhaps a conversion to g_malloc_n() would be neater in places, but
that's merely four years old, and we can't use such newfangled stuff.
This commit only touches allocations with size arguments of the form
sizeof(T), plus two that use 4 instead of sizeof(uint32_t). We can
make the others safe by converting to g_malloc_n() when it becomes
available to us in a couple of years.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Max Reitz <mreitz@redhat.com>
Reviewed-by: Jeff Cody <jcody@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Diffstat (limited to 'block/bochs.c')
-rw-r--r-- | block/bochs.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/block/bochs.c b/block/bochs.c index 6674b27438..199ac2b9af 100644 --- a/block/bochs.c +++ b/block/bochs.c @@ -131,7 +131,7 @@ static int bochs_open(BlockDriverState *bs, QDict *options, int flags, return -EFBIG; } - s->catalog_bitmap = g_try_malloc(s->catalog_size * 4); + s->catalog_bitmap = g_try_new(uint32_t, s->catalog_size); if (s->catalog_size && s->catalog_bitmap == NULL) { error_setg(errp, "Could not allocate memory for catalog"); return -ENOMEM; |