diff --git a/framework/src/fwk_core.c b/framework/src/fwk_core.c index 68a88555816d69eae2c640cbce8a7b5af8c1b9bf..abc28df4b87980b6f3b27e1f5d08fa364122ac03 100644 --- a/framework/src/fwk_core.c +++ b/framework/src/fwk_core.c @@ -1,6 +1,6 @@ /* * Arm SCP/MCP Software - * Copyright (c) 2015-2024, Arm Limited and Contributors. All rights reserved. + * Copyright (c) 2015-2025, Arm Limited and Contributors. All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause * @@ -291,6 +291,10 @@ int __fwk_init(size_t event_count) { struct fwk_event *event_table, *event; + if (event_count == 0) { + return FWK_E_INIT; + } + event_table = fwk_mm_calloc(event_count, sizeof(struct fwk_event)); /* All the event structures are free to be used. */ diff --git a/framework/test/test_fwk_core.c b/framework/test/test_fwk_core.c index 81bba301a7c91961c760a5b34917fb5163dcaded..14725e6536ac9af3da8da53569bd41367c1207ce 100644 --- a/framework/test/test_fwk_core.c +++ b/framework/test/test_fwk_core.c @@ -1,6 +1,6 @@ /* * Arm SCP/MCP Software - * Copyright (c) 2015-2022, Arm Limited and Contributors. All rights reserved. + * Copyright (c) 2015-2025, Arm Limited and Contributors. All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause */ @@ -148,11 +148,17 @@ static void test_case_teardown(void) static void test___fwk_init(void) { int result; - size_t event_count = 2; + size_t event_count; fwk_mm_calloc_return_val = true; + /* Try to initialise with 0 events. */ + event_count = 0; + result = __fwk_init(event_count); + assert(result == FWK_E_INIT); + /* Insert 2 events in the list */ + event_count = 2; result = __fwk_init(event_count); assert(result == FWK_SUCCESS); assert( diff --git a/tools/config/cppcheck/cppcheck_suppress_list.txt b/tools/config/cppcheck/cppcheck_suppress_list.txt index c6104b56437fd3f45a79afdfa115b53d16bb0e3f..be8dc20beeb7bf000d0dd7fda6d221572eb2b95e 100755 --- a/tools/config/cppcheck/cppcheck_suppress_list.txt +++ b/tools/config/cppcheck/cppcheck_suppress_list.txt @@ -36,7 +36,7 @@ preprocessorErrorDirective:*arch/arm/common/src/arch_mm.c:16 preprocessorErrorDirective:*arch/arm/armv8-a/src/arch_mm.c:17 // Cppcheck is not able to parse returned boolean values inside if conditions -internalAstError:*framework/src/fwk_core.c:313 +internalAstError:*framework/src/fwk_core.c:317 // Suppress CMSIS errors *:*/CMSIS*/*