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 13:29:07 +01:00
parent b07a1f40c7
commit 7db8373e08
6 changed files with 14 additions and 10 deletions
+2 -1
View File
@@ -53,6 +53,7 @@
#define LIBVIRT_ALIGN(x) (((x) + __SIZEOF_POINTER__ - 1) & ~(__SIZEOF_POINTER__ - 1))
#define FAMILY_ADDRESS_SIZE(family) ((family) == AF_INET6 ? 16 : 4)
#define G_N_ELEMENTS(Array) (sizeof(Array) / sizeof(*(Array)))
static int
leaseAddressSorter(const void *a,
@@ -595,7 +596,7 @@ nss_module_register(const char *name __attribute__((unused)),
unsigned int *size,
nss_module_unregister_fn *unregister)
{
*size = sizeof(methods) / sizeof(methods[0]);
*size = G_N_ELEMENTS(methods);
*unregister = NULL;
return methods;
}