From: Vincent Bernat Date: Fri, 15 Mar 2019 07:25:09 +0000 (+0100) Subject: lib: use an unique variable as iterator in foreach macro X-Git-Tag: 1.0.4~16 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0ca212866b3c1bf294f495e56da03488bb12fb85;p=thirdparty%2Flldpd.git 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. --- 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)) /**