Fix build warnings -Wmisleading-indentation and -Wdangling-else 80/317080/1
authorYoungjae Cho <y0.cho@samsung.com>
Tue, 24 Dec 2024 02:32:40 +0000 (11:32 +0900)
committerYoungjae Cho <y0.cho@samsung.com>
Tue, 24 Dec 2024 02:41:19 +0000 (11:41 +0900)
1. -Wmisleading-indentation
 /home/abuild/rpmbuild/BUILD/deviced-10.0.0/src/shared/devices.h:137:9:
    warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   137 |         if (!dev) dev = find_device(name); if (check_default(dev)) return -ENODEV; \
       |         ^~
       |         ^~~~~~~~~~~~~~~
 /home/abuild/rpmbuild/BUILD/deviced-10.0.0/src/shared/devices.h:137:44: note:
    ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   137 |         if (!dev) dev = find_device(name); if (check_default(dev)) return -ENODEV; \

   : Fixed them by breaking line.

2. -Wdangling-else
 /home/abuild/rpmbuild/BUILD/deviced-10.0.0/tests/syscommon-plugin-test/display.cc:55:12:
    warning: suggest explicit braces to avoid ambiguous 'else' [-Wdangling-else]
   55 |         if (ret_val == 0 && display_config)

   : The EXPECT_EQ() macro following the above 'if' statement is expanded like below
    if (ret_val == 0 && display_config)
      switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare(
      "display_config->display_dpms_type"
      ,
      "SYSCOMMON_DEVICED_DPMS_TYPE_NONE"
      ,
      display_config->display_dpms_type
      ,
      SYSCOMMON_DEVICED_DPMS_TYPE_NONE
      ))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure,
        "display.cc", 56, gtest_ar.failure_message()) = ::testing::Message()
      ;

   And there is nested, inner 'if-else' statement at the EXPECT_EQ() and this
   generates the warning. Fix it by enclosing the outmost if statement
   with braces.

Change-Id: I4fc835e667302154e4ec165e8611dfad616078ea
Signed-off-by: Youngjae Cho <y0.cho@samsung.com>
src/shared/devices.h
tests/syscommon-plugin-test/display.cc

index d51a42f3c763d5226775979141e7ba3b4ffb0468..6ebb6fc714100530bad1b444da7394532e07a003 100644 (file)
@@ -134,11 +134,17 @@ int check_default(const struct device_ops *dev);
 } while (0)
 
 #define FIND_DEVICE_INT(dev, name) do { \
-       if (!dev) dev = find_device(name); if (check_default(dev)) return -ENODEV; \
+       if (!dev) \
+               dev = find_device(name); \
+       if (check_default(dev)) \
+               return -ENODEV; \
 } while (0)
 
 #define FIND_DEVICE_VOID(dev, name) do { \
-       if (!dev) dev = find_device(name); if (check_default(dev)) return; \
+       if (!dev) \
+               dev = find_device(name); \
+       if (check_default(dev)) \
+               return; \
 } while (0)
 
 #define GET_DEVICE_STATUS(name, defaults, ret) do { \
index 3ace7f0c0bd4adabc0b73967b151e2fe047ef569..7263c3cc789dc710aeb70eb76ad5c2db061e9a16 100644 (file)
@@ -52,6 +52,7 @@ TEST_F(DisplayTest, CheckDisplayDPMSTypeInHeadless)
        }
 
        ret_val = syscommon_plugin_deviced_display_load_config(&display_config);
-       if (ret_val == 0 && display_config)
+       if (ret_val == 0 && display_config) {
                EXPECT_EQ(display_config->display_dpms_type, SYSCOMMON_DEVICED_DPMS_TYPE_NONE);
+       }
 }
\ No newline at end of file