]> git.ipfire.org Git - thirdparty/dbus.git/commitdiff
Use 'continue' keyword in preference to 'goto' where possible
authorSimon McVittie <smcv@collabora.com>
Fri, 9 Sep 2022 15:21:43 +0000 (16:21 +0100)
committerRalf Habacker <ralf.habacker@freenet.de>
Tue, 29 Nov 2022 18:50:06 +0000 (18:50 +0000)
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>
bus/config-parser-trivial.c
bus/config-parser.c
test/internals/dbus-auth-script.c
test/internals/dbus-auth-util.c
test/internals/dbus-message-util.c
test/internals/sha.c

index 9a2087cffc884eb0915211abd02c0f40017b4cc5..a217455690c4f311a13787ef2062c82caa2422d3 100644 (file)
@@ -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));
index 9f2e3c794784ef67b41d868dda5f7dfcc546a9f6..2d2a7ccd0889dfb0836e45c93e7482a7745e7d3b 100644 (file)
@@ -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));
index 61b8f6740fd37f7c7edd2602767b3cc05c7f483d..de81ffb39ed2ebc42b1020714d0c6c683c1feace 100644 (file)
@@ -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:
       {
index bd862b0eef39aea4ae13f4fbd673ac264b67963b..d1916b6ea255ac0d007b81c99bcf60d0c251e3ce 100644 (file)
@@ -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));
index 25237c8507fcbdd84b20900ac643efe772bcd460..8e6fa3737ee96772f8180e95497d4ec7dc70a9b8 100644 (file)
@@ -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",
index 8de77efbec00663ee07ad129aec98346e75cf94c..3954bb70285cd23dd3dbc342d7416c7e57bbc30c 100644 (file)
@@ -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;