qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH 2/3] block: Use g_new() & friends to avoid multi


From: Max Reitz
Subject: Re: [Qemu-devel] [PATCH 2/3] block: Use g_new() & friends to avoid multiplying sizes
Date: Fri, 30 May 2014 20:25:33 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.5.0

On 30.05.2014 18:30, Markus Armbruster wrote:
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,
especially where we do "v = g_malloc(sizeof(*v) * n)", but it's merely
four years old, and we can't use such newfangled stuff.

This commit does not touch allocations with size arguments that don't
use sizeof.  We can make them safe by converting to g_malloc_n() when
the newfangled stuff becomes available to us in a couple of years.

Signed-off-by: Markus Armbruster <address@hidden>
---
  block/bochs.c            | 2 +-
  block/parallels.c        | 2 +-
  block/qcow2-cache.c      | 2 +-
  block/qed-check.c        | 3 +--
  block/rbd.c              | 2 +-
  block/sheepdog.c         | 2 +-
  hw/block/dataplane/ioq.c | 4 ++--
  hw/block/nvme.c          | 8 ++++----
  8 files changed, 12 insertions(+), 13 deletions(-)

Reviewed-by: Max Reitz <address@hidden>



reply via email to

[Prev in Thread] Current Thread [Next in Thread]