]> git.ipfire.org Git - thirdparty/lldpd.git/commitdiff
lib: use an unique variable as iterator in foreach macro
authorVincent Bernat <vincent@bernat.ch>
Fri, 15 Mar 2019 07:25:09 +0000 (08:25 +0100)
committerVincent Bernat <vincent@bernat.ch>
Fri, 15 Mar 2019 07:25:09 +0000 (08:25 +0100)
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

index 45b29f7d3d709c41755b6c95580f8e84bcd0eda0..e78d67efb90378599da1738c269ea4ddd7f99028 100644 (file)
@@ -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))
 
 /**