]> git.ipfire.org Git - thirdparty/libvirt.git/commit
lib: Prefer sizeof(variable) instead of sizeof(type) in memset
authorMichal Privoznik <mprivozn@redhat.com>
Thu, 3 Aug 2023 08:25:43 +0000 (10:25 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Thu, 3 Aug 2023 14:41:19 +0000 (16:41 +0200)
commit1ca3c339a119242b4a511fc9cf7b561a77d2301e
treefefd8e52c17d91df9985a576cf55fad4b0c48acd
parent4f159d426921bb81375fe5404ff88aab9437972a
lib: Prefer sizeof(variable) instead of sizeof(type) in memset

If one of previous commits taught us something, it's that:
sizeof(variable) and sizeof(type) are not the same. Especially
because for live enough code the type might change (e.g. as we
use autoptr more). And since we don't get any warnings when an
incorrect length is passed to memset() it is easy to mess up. But
with sizeof(variable) instead, it's not as easy. Therefore,
switch to using memset(variable, 0, sizeof(*variable)), or its
alternatives, depending on level of pointers.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Claudio Fontana <cfontana@suse.de>
src/qemu/qemu_monitor_json.c
src/qemu/qemu_process.c
src/remote/remote_driver.c
src/storage/storage_driver.c
src/test/test_driver.c