Skip to content

Commit

Permalink
Misc clang-tidy auto fixes (#23445)
Browse files Browse the repository at this point in the history
* Apply readability-redundant-control-flow,readability-redundant-string-init,readability-redundant-string-cstr on linux-x64-tests-clang

* Apply readability-redundant-control-flow,readability-redundant-string-init,readability-redundant-string-cstr on linux-x64-all-clusters-clang

* Apply readability-redundant-control-flow,readability-redundant-string-init,readability-redundant-string-cstr on linux-x64-chip-tool-clang

* Apply modernize-use-bool-literals

* apply performance-for-range-copy

* apply readability-const-return-type

* Fix compile

* Fix compile

* Added clang tidy checks as default and re-sorted the list

* Fix 2 more items found by clang-tidy during CI

* Mass-replace while(1) with while(true)
  • Loading branch information
andy31415 authored and pull[bot] committed Sep 29, 2023
1 parent 62380f8 commit 3923683
Show file tree
Hide file tree
Showing 72 changed files with 162 additions and 164 deletions.
40 changes: 23 additions & 17 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -1,36 +1,42 @@
---
Checks: >
readability-else-after-return,
modernize-use-nullptr,
bugprone-*,
-bugprone-not-null-terminated-result,
-bugprone-unused-return-value,
modernize-use-bool-literals,
modernize-use-nullptr,
performance-for-range-copy,
readability-const-return-type,
readability-else-after-return,
readability-redundant-control-flow,
readability-redundant-string-cstr,
readability-redundant-string-init,
-bugprone-branch-clone,
-bugprone-copy-constructor-init,
-bugprone-easily-swappable-parameters,
-bugprone-reserved-identifier,
-bugprone-macro-parentheses,
-bugprone-forward-declaration-namespace,
-bugprone-forwarding-reference-overload,
-bugprone-undelegated-constructor,
-bugprone-implicit-widening-of-multiplication-result,
-bugprone-narrowing-conversions,
-bugprone-macro-parentheses,
-bugprone-misplaced-widening-cast,
-bugprone-suspicious-include,
-bugprone-narrowing-conversions,
-bugprone-not-null-terminated-result,
-bugprone-reserved-identifier,
-bugprone-signed-char-misuse,
-bugprone-copy-constructor-init,
-bugprone-suspicious-include,
-bugprone-undelegated-constructor,
-bugprone-unused-return-value,
-clang-analyzer-core.CallAndMessage,
-clang-analyzer-core.NonNullParamChecker,
-clang-analyzer-core.NullDereference,
-clang-analyzer-optin.cplusplus.UninitializedObject,
-clang-analyzer-optin.performance,
-clang-analyzer-optin.osx.cocoa.localizability.EmptyLocalizationContextChecker,
-clang-analyzer-deadcode.DeadStores,
-clang-analyzer-cplusplus.Move,
-clang-analyzer-optin.cplusplus.VirtualCall,
-clang-analyzer-security.insecureAPI.strcpy,
-clang-analyzer-deadcode.DeadStores,
-clang-analyzer-nullability.NullablePassedToNonnull,
-clang-analyzer-optin.cplusplus.UninitializedObject,
-clang-analyzer-optin.cplusplus.VirtualCall,
-clang-analyzer-optin.osx.cocoa.localizability.EmptyLocalizationContextChecker,
-clang-analyzer-optin.performance,
-clang-analyzer-optin.performance.Padding,
-clang-analyzer-security.insecureAPI.rand,
-clang-analyzer-core.NonNullParamChecker,
-clang-analyzer-security.insecureAPI.strcpy,
-clang-analyzer-unix.Malloc,
-clang-diagnostic-implicit-int-conversion
WarningsAsErrors: '*'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class StaticSupportedModesManager : public chip::app::Clusters::ModeSelect::Supp
public:
static const StaticSupportedModesManager instance;

const SupportedModesManager::ModeOptionsProvider getModeOptionsProvider(EndpointId endpointId) const override;
SupportedModesManager::ModeOptionsProvider getModeOptionsProvider(EndpointId endpointId) const override;

EmberAfStatus getModeOptionByMode(EndpointId endpointId, uint8_t mode, const ModeOptionStructType ** dataPtr) const override;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const StaticSupportedModesManager::EndpointSpanPair

const StaticSupportedModesManager StaticSupportedModesManager::instance = StaticSupportedModesManager();

const SupportedModesManager::ModeOptionsProvider StaticSupportedModesManager::getModeOptionsProvider(EndpointId endpointId) const
SupportedModesManager::ModeOptionsProvider StaticSupportedModesManager::getModeOptionsProvider(EndpointId endpointId) const
{
for (auto & endpointSpanPair : supportedOptionsByEndpoints)
{
Expand Down
16 changes: 8 additions & 8 deletions examples/all-clusters-app/cc13x2x7_26x2x7/main/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ int AppTask::StartAppTask()
if (sAppEventQueue == NULL)
{
PLAT_LOG("Failed to allocate app event queue");
while (1)
while (true)
;
}

Expand All @@ -157,7 +157,7 @@ int AppTask::StartAppTask()
pdPASS)
{
PLAT_LOG("Failed to create app task");
while (1)
while (true)
;
}
return ret;
Expand Down Expand Up @@ -205,39 +205,39 @@ int AppTask::Init()
if (ret != CHIP_NO_ERROR)
{
PLAT_LOG("PlatformMgr().InitChipStack() failed");
while (1)
while (true)
;
}

ret = ThreadStackMgr().InitThreadStack();
if (ret != CHIP_NO_ERROR)
{
PLAT_LOG("ThreadStackMgr().InitThreadStack() failed");
while (1)
while (true)
;
}

ret = ConnectivityMgr().SetThreadDeviceType(ConnectivityManager::kThreadDeviceType_MinimalEndDevice);
if (ret != CHIP_NO_ERROR)
{
PLAT_LOG("ConnectivityMgr().SetThreadDeviceType() failed");
while (1)
while (true)
;
}

ret = PlatformMgr().StartEventLoopTask();
if (ret != CHIP_NO_ERROR)
{
PLAT_LOG("PlatformMgr().StartEventLoopTask() failed");
while (1)
while (true)
;
}

ret = ThreadStackMgrImpl().StartThreadTask();
if (ret != CHIP_NO_ERROR)
{
PLAT_LOG("ThreadStackMgr().StartThreadTask() failed");
while (1)
while (true)
;
}

Expand Down Expand Up @@ -279,7 +279,7 @@ void AppTask::AppTaskMain(void * pvParameter)

sAppTask.Init();

while (1)
while (true)
{
/* Task pend until we have stuff to do */
if (xQueueReceive(sAppEventQueue, &event, portMAX_DELAY) == pdTRUE)
Expand Down
6 changes: 3 additions & 3 deletions examples/all-clusters-app/cc13x2x7_26x2x7/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ uint32_t heapSize = TOTAL_ICALL_HEAP_SIZE;
// ================================================================================
extern "C" void vApplicationStackOverflowHook(void)
{
while (1)
while (true)
{
;
}
Expand Down Expand Up @@ -85,13 +85,13 @@ int main(void)
{
// can't log until the kernel is started
// PLAT_LOG("GetAppTask().StartAppTask() failed");
while (1)
while (true)
;
}

vTaskStartScheduler();

// Should never get here.
while (1)
while (true)
;
}
2 changes: 1 addition & 1 deletion examples/all-clusters-app/infineon/psoc6/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ void appError(int err)
{
P6_LOG("!!!!!!!!!!!! App Critical Error: %d !!!!!!!!!!!", err);
portDISABLE_INTERRUPTS();
while (1)
while (true)
;
}

Expand Down
4 changes: 2 additions & 2 deletions examples/all-clusters-app/nxp/mw320/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1027,7 +1027,7 @@ void task_main(void * param)
}
}

while (1)
while (true)
{
/* wait for interface up */
os_thread_sleep(os_msec_to_ticks(5000));
Expand Down Expand Up @@ -1131,7 +1131,7 @@ static void rst_args_lt(System::Layer * aSystemLayer, void * aAppState)

void task_test_main(void * param)
{
while (1)
while (true)
{
/* wait for interface up */
os_thread_sleep(os_msec_to_ticks(500));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ int AppTask::StartAppTask()
if (sAppEventQueue == NULL)
{
PLAT_LOG("Failed to allocate app event queue");
while (1)
while (true)
;
}

Expand All @@ -157,7 +157,7 @@ int AppTask::StartAppTask()
pdPASS)
{
PLAT_LOG("Failed to create app task");
while (1)
while (true)
;
}
return ret;
Expand Down Expand Up @@ -205,39 +205,39 @@ int AppTask::Init()
if (ret != CHIP_NO_ERROR)
{
PLAT_LOG("PlatformMgr().InitChipStack() failed");
while (1)
while (true)
;
}

ret = ThreadStackMgr().InitThreadStack();
if (ret != CHIP_NO_ERROR)
{
PLAT_LOG("ThreadStackMgr().InitThreadStack() failed");
while (1)
while (true)
;
}

ret = ConnectivityMgr().SetThreadDeviceType(ConnectivityManager::kThreadDeviceType_MinimalEndDevice);
if (ret != CHIP_NO_ERROR)
{
PLAT_LOG("ConnectivityMgr().SetThreadDeviceType() failed");
while (1)
while (true)
;
}

ret = PlatformMgr().StartEventLoopTask();
if (ret != CHIP_NO_ERROR)
{
PLAT_LOG("PlatformMgr().StartEventLoopTask() failed");
while (1)
while (true)
;
}

ret = ThreadStackMgrImpl().StartThreadTask();
if (ret != CHIP_NO_ERROR)
{
PLAT_LOG("ThreadStackMgr().StartThreadTask() failed");
while (1)
while (true)
;
}

Expand Down Expand Up @@ -279,7 +279,7 @@ void AppTask::AppTaskMain(void * pvParameter)

sAppTask.Init();

while (1)
while (true)
{
/* Task pend until we have stuff to do */
if (xQueueReceive(sAppEventQueue, &event, portMAX_DELAY) == pdTRUE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ uint32_t heapSize = TOTAL_ICALL_HEAP_SIZE;
// ================================================================================
extern "C" void vApplicationStackOverflowHook(void)
{
while (1)
while (true)
{
;
}
Expand Down Expand Up @@ -85,13 +85,13 @@ int main(void)
{
// can't log until the kernel is started
// PLAT_LOG("GetAppTask().StartAppTask() failed");
while (1)
while (true)
;
}

vTaskStartScheduler();

// Should never get here.
while (1)
while (true)
;
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ void appError(int err)
{
P6_LOG("!!!!!!!!!!!! App Critical Error: %d !!!!!!!!!!!", err);
portDISABLE_INTERRUPTS();
while (1)
while (true)
;
}

Expand Down
2 changes: 1 addition & 1 deletion examples/bridge-app/esp32/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ int AddDeviceEndpoint(Device * dev, EmberAfEndpointType * ep, const Span<const E
{
gDevices[index] = dev;
EmberAfStatus ret;
while (1)
while (true)
{
dev->SetEndpointId(gCurrentEndpointId);
ret =
Expand Down
4 changes: 2 additions & 2 deletions examples/bridge-app/linux/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ int AddDeviceEndpoint(Device * dev, EmberAfEndpointType * ep, const Span<const E
{
gDevices[index] = dev;
EmberAfStatus ret;
while (1)
while (true)
{
// Todo: Update this to schedule the work rather than use this lock
DeviceLayer::StackLock lock;
Expand Down Expand Up @@ -754,7 +754,7 @@ void * bridge_polling_thread(void * context)
{
bool light1_added = true;
bool light2_added = false;
while (1)
while (true)
{
if (kbhit())
{
Expand Down
2 changes: 1 addition & 1 deletion examples/chef/esp32/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ extern "C" void app_main(void)
xTaskCreate(&chip_shell_task, "chip_shell", 8192, NULL, 5, NULL);
#endif /* CONFIG_ENABLE_CHIP_SHELL */

while (1)
while (true)
{
vTaskDelay(100 / portTICK_PERIOD_MS);
}
Expand Down
3 changes: 1 addition & 2 deletions examples/chip-tool/commands/common/CHIPCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ const chip::Credentials::AttestationTrustStore * CHIPCommand::sTrustStore = null
chip::Credentials::GroupDataProviderImpl CHIPCommand::sGroupDataProvider{ kMaxGroupsPerFabric, kMaxGroupKeysPerFabric };

namespace {
const CHIP_ERROR GetAttestationTrustStore(const char * paaTrustStorePath,
const chip::Credentials::AttestationTrustStore ** trustStore)
CHIP_ERROR GetAttestationTrustStore(const char * paaTrustStorePath, const chip::Credentials::AttestationTrustStore ** trustStore)
{
if (paaTrustStorePath == nullptr)
{
Expand Down
2 changes: 1 addition & 1 deletion examples/dynamic-bridge-app/linux/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ int AddDeviceEndpoint(Device * dev)
{
gDevices[index] = dev;
EmberAfStatus ret;
while (1)
while (true)
{
// Todo: Update this to schedule the work rather than use this lock
dev->SetEndpointId(gCurrentEndpointId);
Expand Down
2 changes: 1 addition & 1 deletion examples/lighting-app/bouffalolab/bl602/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ void appError(int err)
{
log_error("!!!!!!!!!!!! App Critical Error: %d !!!!!!!!!!!\r\n", err);
portDISABLE_INTERRUPTS();
while (1)
while (true)
;
}

Expand Down
Loading

0 comments on commit 3923683

Please sign in to comment.