Fix issues identified by clang-tidy

- Replace assert with odk_static_assert for checks that can be handled
  at compile time.
- Use explicit bool conversion with memcmp.

Merged from https://widevine-internal-review.googlesource.com/170414

PiperOrigin-RevId: 524277743
Change-Id: I8b32e886e780e80406afceea562be2033d75d340
This commit is contained in:
Googler
2023-04-14 06:40:20 -07:00
committed by Robert Shih
parent a2a27c44ef
commit 89666aeb89
3 changed files with 6 additions and 14 deletions

View File

@@ -19,7 +19,7 @@ extern "C" {
#define ODK_MINOR_VERSION 2
/* ODK Version string. Date changed automatically on each release. */
#define ODK_RELEASE_DATE "ODK v18.2 2023-04-12"
#define ODK_RELEASE_DATE "ODK v18.2 2023-04-14"
/* The lowest version number for an ODK message. */
#define ODK_FIRST_VERSION 16

View File

@@ -201,7 +201,7 @@ bool CoreProvisioningRequestFromMessage(
if (device_id_length > 0) {
uint8_t zero[ODK_DEVICE_ID_LEN_MAX] = {};
if (memcmp(zero, device_id + device_id_length,
ODK_DEVICE_ID_LEN_MAX - device_id_length)) {
ODK_DEVICE_ID_LEN_MAX - device_id_length) != 0) {
return false;
}
core_provisioning_request->device_id.assign(
@@ -233,7 +233,7 @@ bool CoreProvisioning40RequestFromMessage(
}
uint8_t zero[ODK_DEVICE_INFO_LEN_MAX] = {};
if (memcmp(zero, device_info + device_info_length,
ODK_DEVICE_INFO_LEN_MAX - device_info_length)) {
ODK_DEVICE_INFO_LEN_MAX - device_info_length) != 0) {
return false;
}
core_provisioning_request->device_info.assign(
@@ -258,7 +258,7 @@ bool CoreRenewedProvisioningRequestFromMessage(
}
uint8_t zero[ODK_DEVICE_ID_LEN_MAX] = {};
if (memcmp(zero, device_id + device_id_length,
ODK_DEVICE_ID_LEN_MAX - device_id_length)) {
ODK_DEVICE_ID_LEN_MAX - device_id_length) != 0) {
return false;
}
core_provisioning_request->device_id.assign(

View File

@@ -8,20 +8,13 @@
#include <stdio.h>
#include <string.h>
#include "odk_assert.h"
#include "odk_message_priv.h"
/*
* C11 defines static_assert in assert.h. If it is available, force a compile
* time error if the abstract ODK_Message struct size does not match its
* implementation. If static_assert is not available, the runtime assert in
* InitMessage will catch the mismatch at the time a message is initialized.
*/
#ifdef static_assert
static_assert(
odk_static_assert(
sizeof(ODK_Message) >= sizeof(ODK_Message_Impl),
"sizeof(ODK_Message) is too small. You can increase "
"SIZE_OF_ODK_MESSAGE_IMPL in odk_message.h to make it large enough.");
#endif
/*
* Create a message structure that references a separate data buffer. An
@@ -34,7 +27,6 @@ static_assert(
* unchanged by this function.
*/
ODK_Message ODK_Message_Create(uint8_t* buffer, size_t capacity) {
assert(sizeof(ODK_Message) >= sizeof(ODK_Message_Impl));
ODK_Message message;
ODK_Message_Impl* message_impl = (ODK_Message_Impl*)&message;
message_impl->base = buffer;