Browse Source

Add a null statement to prevent some SMARTLIST_FOREACH() bugs.

So we require that SMARTLIST_FOREACH_END() have the name of the loop
variable in it.  But right now the only enforcement for that is to
clear the variable at the end of the loop, which is really not
sufficient: I spent 45 minutes earlier today debugging an issue
where I had said:
   SMARTLIST_FOREACH_BEGIN(spool, spooled_resource_t *, spooled) {
     ...
   } SMARTLIST_FOREACH_END(spool);

This patch makes it so that ONLY loop variables can be used, by
referring to the _sl_idx variable.
Nick Mathewson 7 years ago
parent
commit
dc37ea8b98
1 changed files with 1 additions and 0 deletions
  1. 1 0
      src/common/container.h

+ 1 - 0
src/common/container.h

@@ -224,6 +224,7 @@ char *smartlist_join_strings2(smartlist_t *sl, const char *join,
 
 #define SMARTLIST_FOREACH_END(var)              \
     var = NULL;                                 \
+    (void) var ## _sl_idx;                      \
   } STMT_END
 
 /**