[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [tor/master] Add a null statement to prevent some SMARTLIST_FOREACH() bugs.



commit dc37ea8b9815e75905a6b8b606947866afc9b27b
Author: Nick Mathewson <nickm@xxxxxxxxxxxxxx>
Date:   Mon Mar 13 16:43:30 2017 -0400

    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.
---
 src/common/container.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/common/container.h b/src/common/container.h
index 00c3ca8..826b5d1 100644
--- a/src/common/container.h
+++ b/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
 
 /**

_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits