On Thu, Apr 07, 2016 at 09:31:06 +0200, Michal Privoznik wrote:
What this function does can be written much shorter.
Signed-off-by: Michal Privoznik <mprivozn(a)redhat.com>
---
tools/nss/libvirt_nss.c | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/tools/nss/libvirt_nss.c b/tools/nss/libvirt_nss.c
index de34baf..587b171 100644
--- a/tools/nss/libvirt_nss.c
+++ b/tools/nss/libvirt_nss.c
@@ -263,12 +263,10 @@ move_and_align(void *buf, size_t len, size_t *idx)
char *buffer = buf;
size_t move = LIBVIRT_ALIGN(len);
- if (!idx)
- return buffer + move;
+ if (idx)
+ *idx += move;
- *idx += move;
-
- return buffer + *idx;
+ return buffer + move;
}
But it doesn't seem to be equivalent... The !idx case remains the same,
but in the idx case:
old code:
*idx += move;
return buffer + *idx;
new code:
*idx += move;
return buffer + move;
I guess you need to do something like
if (idx) {
buffer += *idx;
*idx += move;
}
return buffer + move;
Jirka