[BUG] cppcheck results for efi_tcg2.c
Heinrich Schuchardt
heinrich.schuchardt at canonical.com
Fri Nov 26 21:20:51 CET 2021
Hello Masahisa, Ilias, Ruchika,
please, have a look at the cppcheck results for efi_tcg2.c.
[unusedFunction] may be due to checking a single file.
[arithOperationsOnVoidPointer] you might ignore. But the rest should be
addressed.
Best regards
Heinrich
$ cppcheck lib/efi_loader/efi_tcg2.c --enable=all --std=c11
Checking lib/efi_loader/efi_tcg2.c ...
Checking lib/efi_loader/efi_tcg2.c: __ASSEMBLY__...
lib/efi_loader/efi_tcg2.c:1537:6: style: Local variable 'buffer' shadows
outer variable [shadowVariable]
u8 buffer[TPM2_SHA512_DIGEST_SIZE] = { 0 };
^
lib/efi_loader/efi_tcg2.c:1497:8: note: Shadowed declaration
void *buffer;
^
lib/efi_loader/efi_tcg2.c:1537:6: note: Shadow variable
u8 buffer[TPM2_SHA512_DIGEST_SIZE] = { 0 };
^
include/efi_api.h:991:23: portability: '(void*)blk' is of type 'void *'.
When using void pointers in calculations, the behaviour is undefined.
[arithOperationsOnVoidPointer]
return ((void *)blk) + sizeof(*blk) +
^
include/efi_api.h:991:38: portability: '((void*)blk)+sizeof(*blk)' is of
type 'void *'. When using void pointers in calculations, the behaviour
is undefined. [arithOperationsOnVoidPointer]
return ((void *)blk) + sizeof(*blk) +
^
lib/efi_loader/efi_tcg2.c:858:55: portability: 'event_log.buffer' is of
type 'void *'. When using void pointers in calculations, the behaviour
is undefined. [arithOperationsOnVoidPointer]
*event_log_last_entry = (uintptr_t)(event_log.buffer + event_log.pos -
^
lib/efi_loader/efi_tcg2.c:858:71: portability:
'event_log.buffer+event_log.pos' is of type 'void *'. When using void
pointers in calculations, the behaviour is undefined.
[arithOperationsOnVoidPointer]
*event_log_last_entry = (uintptr_t)(event_log.buffer + event_log.pos -
^
lib/efi_loader/efi_tcg2.c:1016:34: portability: 'efi' is of type 'void
*'. When using void pointers in calculations, the behaviour is
undefined. [arithOperationsOnVoidPointer]
nt = (IMAGE_NT_HEADERS32 *)(efi + dos->e_lfanew);
^
lib/efi_loader/efi_tcg2.c:1644:16: portability: 'buffer' is of type
'void *'. When using void pointers in calculations, the behaviour is
undefined. [arithOperationsOnVoidPointer]
memset(buffer + spec_event_size, 0, 1);
^
Heinrich: For writing a single byte you should use an assignment after
converting to u8* instead of calling a library function.
lib/efi_loader/efi_tcg2.c:1359:11: style: Variable 'hash_sz' is assigned
a value that is never used. [unreadVariable]
hash_sz =
^
lib/efi_loader/efi_tcg2.c:1439:13: style: Variable 'event_type' is
assigned a value that is never used. [unreadVariable]
event_type = get_unaligned_le32(&event->event_type);
^
lib/efi_loader/efi_tcg2.c:2223:0: style: The function
'efi_tcg2_measure_efi_app_exit' is never used. [unusedFunction]
^
lib/efi_loader/efi_tcg2.c:2170:0: style: The function
'efi_tcg2_measure_efi_app_invocation' is never used. [unusedFunction]
^
lib/efi_loader/efi_tcg2.c:2277:0: style: The function
'efi_tcg2_notify_exit_boot_services_failed' is never used. [unusedFunction]
^
lib/efi_loader/efi_tcg2.c:2358:0: style: The function
'efi_tcg2_register' is never used. [unusedFunction]
^
lib/efi_loader/efi_tcg2.c:951:0: style: The function
'tcg2_measure_pe_image' is never used. [unusedFunction]
More information about the U-Boot
mailing list