From 0ca212866b3c1bf294f495e56da03488bb12fb85 Mon Sep 17 00:00:00 2001 From: Vincent Bernat Date: Fri, 15 Mar 2019 08:25:09 +0100 Subject: [PATCH] lib: use an unique variable as iterator in foreach macro This lessen the chance of the `iter` variable to shadow a user-defined variable. This is also a tentative to help #312, even if the scope of the `iter` variable should ensure we can nest two loops without any issue. --- src/lib/lldpctl.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/lib/lldpctl.h b/src/lib/lldpctl.h index 45b29f7d..e78d67ef 100644 --- a/src/lib/lldpctl.h +++ b/src/lib/lldpctl.h @@ -1035,10 +1035,10 @@ lldpctl_atom_t *lldpctl_atom_iter_value(lldpctl_atom_t *atom, lldpctl_atom_iter_ * reference count of the provided value is decremented. If you need to use it * outside of the loop, you need to increment it. */ -#define lldpctl_atom_foreach(atom, value) \ - for (lldpctl_atom_iter_t *iter = lldpctl_atom_iter(atom); \ - iter && (value = lldpctl_atom_iter_value(atom, iter)); \ - iter = lldpctl_atom_iter_next(atom, iter), \ +#define lldpctl_atom_foreach(atom, value) \ + for (lldpctl_atom_iter_t *iter##_LINE_ = lldpctl_atom_iter(atom); \ + iter##_LINE_ && (value = lldpctl_atom_iter_value(atom, iter##_LINE_)); \ + iter##_LINE_ = lldpctl_atom_iter_next(atom, iter##_LINE_), \ lldpctl_atom_dec_ref(value)) /** -- 2.39.5