瀏覽代碼

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 年之前
父節點
當前提交
dc37ea8b98
共有 1 個文件被更改,包括 1 次插入0 次删除
  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
 
 /**