Skip to content

Commit

Permalink
fix: fix CodeQL issues
Browse files Browse the repository at this point in the history
  • Loading branch information
nsonanh committed Sep 11, 2023
1 parent fbd1a1f commit d81080f
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/dhp/format/fields.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@
#include "limitations.h"

void resolve_fieldname(const field_t *field, char* dst) {
// Get field if field's data type is Int8 (0x01)
if (field->dataType == STI_INT8) {
switch (field->id) {
CASE_FIELDNAME(DHP_INT8_MAM_REMOVAL_DELTA, "Min Removal")
CASE_FIELDNAME(DHP_INT8_MAM_APPROVAL_DELTA, "Min Approval")
CASE_DEFAULT()
}
}

// Resolve field name if field's data type is UInt8 (0x02)
if (field->dataType == STI_UINT8) {
switch (field->id) {
CASE_FIELDNAME(DHP_UINT8_TXN_MESSAGE_TYPE, "Message Type")
Expand All @@ -40,15 +43,19 @@ void resolve_fieldname(const field_t *field, char* dst) {
CASE_FIELDNAME(DHP_UINT8_MD_RESTRICT_FLAG, "Restrictable")
CASE_FIELDNAME(DHP_UINT8_MAM_ADD_COUNT, "Address Add Num")
CASE_FIELDNAME(DHP_UINT8_MAM_DEL_COUNT, "Address Del Num")
CASE_DEFAULT()
}
}

// Resolve field name if field's data type is Int16 (0x03)
if (field->dataType == STI_INT16) {
switch (field->id) {
CASE_FIELDNAME(DHP_INT16_VALUE_DELTA, "Value Size Delta")
CASE_DEFAULT()
}

Check notice

Code scanning / CodeQL

No trivial switch statements Note

This switch statement should either handle more cases, or be rewritten as an if statement.
}

// Resolve field name if field's data type is UInt16 (0x04)
if (field->dataType == STI_UINT16) {
switch (field->id) {
CASE_FIELDNAME(DHP_UINT16_TRANSACTION_TYPE, "Transaction Type")
Expand All @@ -58,16 +65,20 @@ void resolve_fieldname(const field_t *field, char* dst) {
CASE_FIELDNAME(DHP_UINT16_AR_RESTRICT_TYPE, "Restriction Flag")
CASE_FIELDNAME(DHP_UINT16_AR_RESTRICT_DIRECTION, "Restriction Flag")
CASE_FIELDNAME(DHP_UINT16_AR_RESTRICT_OPERATION, "Restriction Flag")
CASE_DEFAULT()
}
}

// Resolve field name if field's data type is UInt32 (0x05)
if (field->dataType == STI_UINT32) {
switch (field->id) {
CASE_FIELDNAME(DHP_UINT32_VKL_START_POINT, "Start point")
CASE_FIELDNAME(DHP_UINT32_VKL_END_POINT, "End point")
CASE_DEFAULT()
}
}

// Resolve field name if field's data type is UInt64 (0x06)
if (field->dataType == STI_UINT64) {
switch (field->id) {
CASE_FIELDNAME(DHP_UINT64_DURATION, "Duration")
Expand All @@ -76,83 +87,104 @@ void resolve_fieldname(const field_t *field, char* dst) {
CASE_FIELDNAME(DHP_UINT64_NS_ID, "Namespace ID")
CASE_FIELDNAME(DHP_UINT64_MOSAIC_ID, "Mosaic ID")
CASE_FIELDNAME(DHP_UINT64_METADATA_KEY, "Metadata Key")
CASE_DEFAULT()
}
}

// Resolve field name if field's data type is Hash256 (0x07)
if (field->dataType == STI_HASH256) {
switch (field->id) {
CASE_FIELDNAME(DHP_HASH256_AGG_HASH, "Agg. Tx Hash")
CASE_FIELDNAME(DHP_HASH256_HL_HASH, "Tx Hash")
CASE_DEFAULT()
}
}

// Resolve field name if field's data type is Public Key (0x08)
if (field->dataType == STI_PUBLIC_KEY) {
switch (field->id) {
CASE_FIELDNAME(DHP_PUBLICKEY_ACCOUNT_KEY_LINK, "Linked Acct. PbK")
CASE_FIELDNAME(DHP_PUBLICKEY_NODE_KEY_LINK, "Linked Node PbK")
CASE_FIELDNAME(DHP_PUBLICKEY_VOTING_KEY_LINK, "Linked Vot. PbK")
CASE_FIELDNAME(DHP_PUBLICKEY_VRF_KEY_LINK, "Linked Vrf PbK")
CASE_DEFAULT()
}
}

// Resolve field name if field's data type is Address (0x09)
if (field->dataType == STI_ADDRESS) {
switch (field->id) {
CASE_FIELDNAME(DHP_STR_RECIPIENT_ADDRESS, "Recipient")
CASE_FIELDNAME(DHP_STR_METADATA_ADDRESS, "Target Address")
CASE_FIELDNAME(DHP_STR_ADDRESS, "Address")
CASE_DEFAULT()
}
}

// Resolve field name if field's data type is Mosaic Currency (0xA1)
if (field->dataType == STI_MOSAIC_CURRENCY) {
switch (field->id) {
CASE_FIELDNAME(DHP_MOSAIC_AMOUNT, "Amount")
CASE_FIELDNAME(DHP_MOSAIC_HL_QUANTITY, "Lock Quantity")
CASE_DEFAULT()
}
}

// Resolve field name if field's data type is DHP Currency (0xA0)
if (field->dataType == STI_DHP) {
switch (field->id) {
CASE_FIELDNAME(DHP_UINT64_TXN_FEE, "Fee")
CASE_DEFAULT()
}

Check notice

Code scanning / CodeQL

No trivial switch statements Note

This switch statement should either handle more cases, or be rewritten as an if statement.
}

// Resolve field name if field's data type is Message (0xA2)
if (field->dataType == STI_MESSAGE) {
switch (field->id) {
CASE_FIELDNAME(DHP_STR_TXN_MESSAGE, "Message")
CASE_FIELDNAME(DHP_STR_METADATA_VALUE, "Value")
CASE_DEFAULT()
}
}

// Resolve field name if field's data type is Hex Message (0xA4)
if (field->dataType == STI_HEX_MESSAGE) {
switch (field->id) {
CASE_FIELDNAME(DHP_STR_TXN_HARVESTING, "Harvesting Message")
CASE_FIELDNAME(DHP_STR_TXN_HARVESTING_1, "Harvest. Msg 1")
CASE_FIELDNAME(DHP_STR_TXN_HARVESTING_2, "Harvest. Msg 2")
CASE_FIELDNAME(DHP_STR_TXN_HARVESTING_3, "Harvest. Msg 3")
CASE_DEFAULT()
}
}

// Resolve field name if field's data type is STR (0x17)
if (field->dataType == STI_STR) {
switch (field->id) {
CASE_FIELDNAME(DHP_UNKNOWN_MOSAIC, "Unknown Mosaic")
CASE_FIELDNAME(DHP_STR_RECIPIENT_ADDRESS, "Recipient")
CASE_FIELDNAME(DHP_STR_NAMESPACE, "Name")
CASE_DEFAULT()
}
}

// Resolve field name if field's data type is UInt8 Addition (0xA5)
if (field->dataType == STI_UINT8_ADDITION) {
switch (field->id) {
CASE_FIELDNAME(DHP_UINT8_AA_RESTRICTION, "Addition Count")
CASE_FIELDNAME(DHP_UINT8_AM_RESTRICTION, "Addition Count")
CASE_FIELDNAME(DHP_UINT8_AO_RESTRICTION, "Addition Count")
CASE_DEFAULT()
}
}

// Resolve field name if field's data type is UInt8 Deletion (0xA6)
if (field->dataType == STI_UINT8_DELETION) {
switch (field->id) {
CASE_FIELDNAME(DHP_UINT8_AA_RESTRICTION, "Deletion Count")
CASE_FIELDNAME(DHP_UINT8_AM_RESTRICTION, "Deletion Count")
CASE_FIELDNAME(DHP_UINT8_AO_RESTRICTION, "Deletion Count")
CASE_DEFAULT()
}
}

Expand Down
1 change: 1 addition & 0 deletions src/dhp/format/fields.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ typedef struct {

// Simple macro for building more readable switch statements
#define CASE_FIELDNAME(v,src) case v: snprintf(dst, MAX_FIELDNAME_LEN, "%s", src); return;
#define CASE_DEFAULT() default: break;

void resolve_fieldname(const field_t *field, char* dst);

Expand Down

0 comments on commit d81080f

Please sign in to comment.