diff options
author | Simon McVittie <smcv@collabora.com> | 2022-09-09 16:21:43 +0100 |
---|---|---|
committer | Ralf Habacker <ralf.habacker@freenet.de> | 2022-11-29 18:50:06 +0000 |
commit | 54b56ab875fc413d56d07f04b447c02390de0efb (patch) | |
tree | 360426f9bb5519ad5a6617b4a20720d11cff59af /test | |
parent | 2f9d987c0a5dacbf647c4328737e0dda380048eb (diff) | |
download | dbus-54b56ab875fc413d56d07f04b447c02390de0efb.tar.gz |
Use 'continue' keyword in preference to 'goto' where possible
In some more complicated loops, we do need to use 'goto' to exit from
an inner loop, or to jump to cleanup or an increment of an iterator
immediately before the next loop iteration. However, in these simple
cases, jumping to a label immediately before the 'while' keyword is
unnecessary: we can use an equivalent 'continue' statement for flow
control.
This makes it easier for maintainers to notice the loops where we are
doing something more complicated, which still use 'goto', and know
that they need to pay more attention in those cases.
Signed-off-by: Simon McVittie <smcv@collabora.com>
Diffstat (limited to 'test')
-rw-r--r-- | test/internals/dbus-auth-script.c | 11 | ||||
-rw-r--r-- | test/internals/dbus-auth-util.c | 3 | ||||
-rw-r--r-- | test/internals/dbus-message-util.c | 3 | ||||
-rw-r--r-- | test/internals/sha.c | 26 |
4 files changed, 25 insertions, 18 deletions
diff --git a/test/internals/dbus-auth-script.c b/test/internals/dbus-auth-script.c index 61b8f674..de81ffb3 100644 --- a/test/internals/dbus-auth-script.c +++ b/test/internals/dbus-auth-script.c @@ -307,7 +307,6 @@ _dbus_auth_script_run (const DBusString *filename) state = DBUS_AUTH_STATE_NEED_DISCONNECT; line_no = 0; - next_iteration: while (_dbus_string_pop_line (&file, &line)) { line_no += 1; @@ -336,20 +335,20 @@ _dbus_auth_script_run (const DBusString *filename) if (_dbus_string_get_length (&line) == 0) { /* empty line */ - goto next_iteration; + continue; } else if (_dbus_string_starts_with_c_str (&line, "#")) { /* Ignore this comment */ - goto next_iteration; + continue; } #ifdef DBUS_WIN else if (_dbus_string_starts_with_c_str (&line, "WIN_ONLY")) { /* Ignore this line */ - goto next_iteration; + continue; } else if (_dbus_string_starts_with_c_str (&line, "UNIX_ONLY")) @@ -365,7 +364,7 @@ _dbus_auth_script_run (const DBusString *filename) "UNIX_ONLY")) { /* Ignore this line */ - goto next_iteration; + continue; } else if (_dbus_string_starts_with_c_str (&line, "WIN_ONLY")) @@ -837,7 +836,7 @@ _dbus_auth_script_run (const DBusString *filename) else goto parse_failed; - goto next_iteration; /* skip parse_failed */ + continue; /* skip parse_failed */ parse_failed: { diff --git a/test/internals/dbus-auth-util.c b/test/internals/dbus-auth-util.c index bd862b0e..d1916b6e 100644 --- a/test/internals/dbus-auth-util.c +++ b/test/internals/dbus-auth-util.c @@ -82,7 +82,6 @@ process_test_subdir (const DBusString *test_base_dir, _dbus_test_diag ("Testing %s:", subdir); - next: while (_dbus_directory_get_next_file (dir, &filename, &error)) { DBusString full_path; @@ -101,7 +100,7 @@ process_test_subdir (const DBusString *test_base_dir, _dbus_verbose ("Skipping non-.auth-script file %s\n", _dbus_string_get_const_data (&filename)); _dbus_string_free (&full_path); - goto next; + continue; } _dbus_test_diag (" %s", _dbus_string_get_const_data (&filename)); diff --git a/test/internals/dbus-message-util.c b/test/internals/dbus-message-util.c index 25237c85..8e6fa373 100644 --- a/test/internals/dbus-message-util.c +++ b/test/internals/dbus-message-util.c @@ -510,7 +510,6 @@ process_test_subdir (const DBusString *test_base_dir, _dbus_test_diag ("Testing %s:", subdir); - next: while (_dbus_directory_get_next_file (dir, &filename, &error)) { DBusString full_path; @@ -531,7 +530,7 @@ process_test_subdir (const DBusString *test_base_dir, _dbus_verbose ("Skipping non-.message-raw file %s\n", _dbus_string_get_const_data (&filename)); _dbus_string_free (&full_path); - goto next; + continue; } _dbus_test_diag (" %s", diff --git a/test/internals/sha.c b/test/internals/sha.c index 8de77efb..3954bb70 100644 --- a/test/internals/sha.c +++ b/test/internals/sha.c @@ -188,22 +188,27 @@ get_next_expected_result (DBusString *results, if (!_dbus_string_init (&line)) _dbus_test_fatal ("no memory"); - next_iteration: while (_dbus_string_pop_line (results, &line)) { _dbus_string_delete_leading_blanks (&line); if (_dbus_string_get_length (&line) == 0) - goto next_iteration; + { + continue; + } else if (_dbus_string_starts_with_c_str (&line, "#")) - goto next_iteration; + { + continue; + } else if (_dbus_string_starts_with_c_str (&line, "H>")) { /* don't print */ } else if (_dbus_string_starts_with_c_str (&line, "D>") || _dbus_string_starts_with_c_str (&line, "<D")) - goto next_iteration; + { + continue; + } else { int i; @@ -324,7 +329,6 @@ process_test_data (const char *test_data_dir) success_count = 0; line_no = 0; - next_iteration: while (_dbus_string_pop_line (&tests, &line)) { line_no += 1; @@ -332,9 +336,13 @@ process_test_data (const char *test_data_dir) _dbus_string_delete_leading_blanks (&line); if (_dbus_string_get_length (&line) == 0) - goto next_iteration; + { + continue; + } else if (_dbus_string_starts_with_c_str (&line, "#")) - goto next_iteration; + { + continue; + } else if (_dbus_string_starts_with_c_str (&line, "H>")) { _dbus_test_diag ("SHA-1: %s", _dbus_string_get_const_data (&line)); @@ -353,7 +361,9 @@ process_test_data (const char *test_data_dir) } else if (_dbus_string_starts_with_c_str (&line, "D>") || _dbus_string_starts_with_c_str (&line, "<D")) - goto next_iteration; + { + continue; + } else { DBusString test; |