Use G_N_ELEMENTS() more

In a few places we still use the good old:

  sizeof(var) / sizeof(var[0])
  sizeof(var) / sizeof(int)

The G_N_ELEMENTS() macro is preferred though. In a few places we
don't link with glib, so provide the macro definition.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Kristina Hanicova <khanicov@redhat.com>
This commit is contained in:
Michal Privoznik
2023-03-13 10:43:50 +01:00
parent b07a1f40c7
commit 7db8373e08
6 changed files with 14 additions and 10 deletions

View File

@@ -7,6 +7,8 @@
#include <libvirt/libvirt.h>
#include <libvirt/virterror.h>
#define G_N_ELEMENTS(Array) (sizeof(Array) / sizeof(*(Array)))
static void
showError(virConnectPtr conn)
{
@@ -205,7 +207,7 @@ static int credTypes[] = {
/* The auth struct that will be passed to virConnectOpenAuth */
static virConnectAuth auth = {
credTypes,
sizeof(credTypes) / sizeof(int),
G_N_ELEMENTS(credTypes),
authCallback,
NULL, /* cbdata will be initialized in main */
};