
On Fri, Mar 18, 2016 at 17:42:29 +0100, Martin Kletzander wrote:
Every aligning requires at least one cast and it's hard to read. Let's make a function that makes sure the pointer is moved according to the alignment and use that to move throughout the data buffer.
Signed-off-by: Martin Kletzander <mkletzan@redhat.com> --- tools/nss/libvirt_nss.c | 51 ++++++++++++++++++++++++++++++++----------------- 1 file changed, 33 insertions(+), 18 deletions(-)
diff --git a/tools/nss/libvirt_nss.c b/tools/nss/libvirt_nss.c index ba3bb31b3569..c9909901786d 100644 --- a/tools/nss/libvirt_nss.c +++ b/tools/nss/libvirt_nss.c @@ -252,17 +252,31 @@ _nss_libvirt_gethostbyname2_r(const char *name, int af, struct hostent *result,
[...]
_nss_libvirt_gethostbyname3_r(const char *name, int af, struct hostent *result, char *buffer, size_t buflen, int *errnop, int *herrnop, int32_t *ttlp, char **canonp) { enum nss_status ret = NSS_STATUS_UNAVAIL; - char *r_name, **r_aliases, *r_addr, **r_addr_list; + char *r_name, **r_aliases, *r_addr, *r_addr_next, **r_addr_list; leaseAddress *addr = NULL; size_t naddr, i; bool found = false; - size_t nameLen, need, idx; + size_t nameLen, need, idx = 0;
You've initialized it in this function ...
int alen; int r;
[...]
@@ -420,25 +438,22 @@ _nss_libvirt_gethostbyname4_r(const char *name, struct gaih_addrtuple **pat,
... but not in this function ...
/* First, append name */ r_name = buffer; memcpy(r_name, name, nameLen + 1); - idx = ALIGN(nameLen + 1); -
... and you remove the initialization here ...
/* Second, append addresses */ - r_tuple_first = (struct gaih_addrtuple*) (buffer + idx); + r_tuple_first = move_and_align(buffer, nameLen + 1, &idx);
... and use it here: nss/libvirt_nss.c: In function '_nss_libvirt_gethostbyname4_r': nss/libvirt_nss.c:264:10: error: 'idx' may be used uninitialized in this function [-Werror=maybe-uninitialized] *idx += move;
for (i = 0; i < naddr; i++) { int family = addr[i].af;
Peter