From a09713c7956b300382e5ce4b7cea3b08cf5553e4 Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Tue, 25 Aug 2020 22:50:18 +0200 Subject: [PATCH] test cleanup: Annotate file removal after a failed creation Let static analyzers know that it's ok if remove() fails here. Signed-off-by: Gilles Peskine --- tests/suites/test_suite_psa_its.function | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/tests/suites/test_suite_psa_its.function b/tests/suites/test_suite_psa_its.function index b6cc488a6..a7ce7b1d4 100644 --- a/tests/suites/test_suite_psa_its.function +++ b/tests/suites/test_suite_psa_its.function @@ -40,16 +40,23 @@ static psa_storage_uid_t uid_max = 0; static void cleanup( void ) { + /* Call remove() on all the files that a test might have created. + * We ignore the error if the file exists but remove() fails because + * it can't be checked portably (except by attempting to open the file + * first, which is needlessly slow and complicated here). A failure of + * remove() on an existing file is very unlikely anyway and would not + * have significant consequences other than perhaps failing the next + * test case. */ char filename[PSA_ITS_STORAGE_FILENAME_LENGTH]; psa_storage_uid_t uid; for( uid = 0; uid < uid_max; uid++ ) { psa_its_fill_filename( uid, filename ); - remove( filename ); + (void) remove( filename ); } psa_its_fill_filename( (psa_storage_uid_t)( -1 ), filename ); - remove( filename ); - remove( PSA_ITS_STORAGE_TEMP ); + (void) remove( filename ); + (void) remove( PSA_ITS_STORAGE_TEMP ); uid_max = 0; }