From 3a5a107fa7ae1d3287dafe1ad21dbf5d6dadc7b5 Mon Sep 17 00:00:00 2001 From: Paul Elliott Date: Thu, 17 Dec 2020 18:33:40 +0000 Subject: [PATCH] Correct fix for potential truncation This was a false positive caused by the compiler seeing the %08lx specifiers and judging the output on that, rather than the numbers being fed in. Given these are going to be maximum 32 bit numbers, then better to use %08x, which keeps -Wformat-truncation=2 happy as well. Signed-off-by: Paul Elliott --- library/psa_its_file.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/library/psa_its_file.c b/library/psa_its_file.c index 8dff7834d..7798da615 100644 --- a/library/psa_its_file.c +++ b/library/psa_its_file.c @@ -47,11 +47,10 @@ #define PSA_ITS_STORAGE_PREFIX "" #endif -#define PSA_ITS_STORAGE_FILENAME_PATTERN "%08lx%08lx" +#define PSA_ITS_STORAGE_FILENAME_PATTERN "%08x%08x" #define PSA_ITS_STORAGE_SUFFIX ".psa_its" #define PSA_ITS_STORAGE_FILENAME_LENGTH \ ( sizeof( PSA_ITS_STORAGE_PREFIX ) - 1 + /*prefix without terminating 0*/ \ - 16 + /*UID (64-bit number in hex)*/ \ 16 + /*UID (64-bit number in hex)*/ \ sizeof( PSA_ITS_STORAGE_SUFFIX ) - 1 + /*suffix without terminating 0*/ \ 1 /*terminating null byte*/ ) @@ -88,8 +87,8 @@ static void psa_its_fill_filename( psa_storage_uid_t uid, char *filename ) mbedtls_snprintf( filename, PSA_ITS_STORAGE_FILENAME_LENGTH, "%s" PSA_ITS_STORAGE_FILENAME_PATTERN "%s", PSA_ITS_STORAGE_PREFIX, - (unsigned long) ( uid >> 32 ), - (unsigned long) ( uid & 0xffffffff ), + (unsigned) ( uid >> 32 ), + (unsigned) ( uid & 0xffffffff ), PSA_ITS_STORAGE_SUFFIX ); }