From: Simon McVittie Date: Fri, 9 Sep 2022 15:21:43 +0000 (+0100) Subject: Use 'continue' keyword in preference to 'goto' where possible X-Git-Tag: dbus-1.15.4~24^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=54b56ab875fc413d56d07f04b447c02390de0efb;p=thirdparty%2Fdbus.git 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 --- diff --git a/bus/config-parser-trivial.c b/bus/config-parser-trivial.c index 9a2087cff..a21745569 100644 --- a/bus/config-parser-trivial.c +++ b/bus/config-parser-trivial.c @@ -552,7 +552,6 @@ process_test_valid_subdir (const DBusString *test_base_dir, else _dbus_test_diag ("Testing unknown files:"); - next: while (_dbus_directory_get_next_file (dir, &filename, &error)) { DBusString full_path; @@ -572,7 +571,7 @@ process_test_valid_subdir (const DBusString *test_base_dir, _dbus_verbose ("Skipping non-.conf 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/bus/config-parser.c b/bus/config-parser.c index 9f2e3c794..2d2a7ccd0 100644 --- a/bus/config-parser.c +++ b/bus/config-parser.c @@ -3239,7 +3239,6 @@ process_test_valid_subdir (const DBusString *test_base_dir, else _dbus_test_diag ("Testing unknown files:"); - next: while (_dbus_directory_get_next_file (dir, &filename, &error)) { DBusString full_path; @@ -3259,7 +3258,7 @@ process_test_valid_subdir (const DBusString *test_base_dir, _dbus_verbose ("Skipping non-.conf 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)); @@ -3556,7 +3555,6 @@ all_are_equiv (const DBusString *target_directory) _dbus_test_diag ("Comparing equivalent files:"); - next: while (_dbus_directory_get_next_file (dir, &filename, &error)) { DBusString full_path; @@ -3575,7 +3573,7 @@ all_are_equiv (const DBusString *target_directory) _dbus_verbose ("Skipping non-.conf 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-auth-script.c b/test/internals/dbus-auth-script.c index 61b8f6740..de81ffb39 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 bd862b0ee..d1916b6ea 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 25237c850..8e6fa3737 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 8de77efbe..3954bb702 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, "")) { _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, "