mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-12-06 19:41:15 +01:00
Change all SMARTLIST_FOREACH loops of >=10 lines to use BEGIN/END
The SMARTLIST_FOREACH macro is more convenient than BEGIN/END when you have a nice short loop body, but using it for long bodies makes your preprocessor tell the compiler that all the code is on the same line. That causes grief, since compiler warnings and debugger lines will all refer to that one line. So, here's a new style rule: SMARTLIST_FOREACH blocks need to be short.
This commit is contained in:
+2
-3
@@ -131,8 +131,7 @@ rm_rf(const char *dir)
|
||||
|
||||
elements = tor_listdir(dir);
|
||||
if (elements) {
|
||||
SMARTLIST_FOREACH(elements, const char *, cp,
|
||||
{
|
||||
SMARTLIST_FOREACH_BEGIN(elements, const char *, cp) {
|
||||
char *tmp = NULL;
|
||||
tor_asprintf(&tmp, "%s"PATH_SEPARATOR"%s", dir, cp);
|
||||
if (0 == stat(tmp,&st) && (st.st_mode & S_IFDIR)) {
|
||||
@@ -143,7 +142,7 @@ rm_rf(const char *dir)
|
||||
}
|
||||
}
|
||||
tor_free(tmp);
|
||||
});
|
||||
} SMARTLIST_FOREACH_END(cp);
|
||||
SMARTLIST_FOREACH(elements, char *, cp, tor_free(cp));
|
||||
smartlist_free(elements);
|
||||
}
|
||||
|
||||
@@ -2604,8 +2604,7 @@ test_util_split_lines(void *ptr)
|
||||
j = 0;
|
||||
log_info(LD_GENERAL, "Splitting test %d of length %d",
|
||||
i, tests[i].orig_length);
|
||||
SMARTLIST_FOREACH(sl, const char *, line,
|
||||
{
|
||||
SMARTLIST_FOREACH_BEGIN(sl, const char *, line) {
|
||||
/* Check we have not got too many lines */
|
||||
test_assert(j < MAX_SPLIT_LINE_COUNT);
|
||||
/* Check that there actually should be a line here */
|
||||
@@ -2615,7 +2614,7 @@ test_util_split_lines(void *ptr)
|
||||
/* Check that the line is as expected */
|
||||
test_streq(line, tests[i].split_line[j]);
|
||||
j++;
|
||||
});
|
||||
} SMARTLIST_FOREACH_END(line);
|
||||
/* Check that we didn't miss some lines */
|
||||
test_eq_ptr(NULL, tests[i].split_line[j]);
|
||||
tor_free(orig_line);
|
||||
|
||||
Reference in New Issue
Block a user