Skip to content

Commit

Permalink
fix: appease the tyran codacy
Browse files Browse the repository at this point in the history
  • Loading branch information
jean-roland committed Mar 5, 2024
1 parent 5636bfa commit 30f0406
Showing 1 changed file with 21 additions and 17 deletions.
38 changes: 21 additions & 17 deletions src/transport/raweth/link.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#if Z_FEATURE_RAWETH_TRANSPORT == 1

#define RAWETH_CFG_TUPLE_SEPARATOR '#'
#define RAWETH_CFG_LIST_SEPARATOR ','
#define RAWETH_CFG_LIST_SEPARATOR ","

#define RAWETH_CONFIG_ARGC 4

Expand Down Expand Up @@ -120,15 +120,15 @@ static size_t _z_valid_mapping_raweth(_z_str_intmap_t *config) {
size_t size = 0;
strcpy(s_mapping, cfg_str);
// Parse list
char delim[] = {RAWETH_CFG_LIST_SEPARATOR};
const char *delim = RAWETH_CFG_LIST_SEPARATOR;
char *entry = strtok(s_mapping, delim);

Check warning

Code scanning / Cppcheck (reported by Codacy)

strtok is MT-unsafe Warning

strtok is MT-unsafe
while (entry != NULL) {
// Check entry
if (!_z_valid_mapping_entry(entry)) {
zp_free(s_mapping);
return 0;
}
size += 1;
size++;
entry = strtok(NULL, delim);

Check warning

Code scanning / Cppcheck (reported by Codacy)

strtok is MT-unsafe Warning

strtok is MT-unsafe
}
// Clean up
Expand All @@ -155,14 +155,14 @@ static int8_t _z_get_mapping_raweth(_z_str_intmap_t *config, _zp_raweth_mapping_
}
size_t idx = 0;
// Parse list
char delim[] = {RAWETH_CFG_LIST_SEPARATOR};
const char *delim = RAWETH_CFG_LIST_SEPARATOR;
char *entry = strtok(s_mapping, delim);

Check warning

Code scanning / Cppcheck (reported by Codacy)

strtok is MT-unsafe Warning

strtok is MT-unsafe
while ((entry != NULL) && (idx < _zp_raweth_mapping_array_len(array))) {
// Copy data into array
_Z_CLEAN_RETURN_IF_ERR(_z_get_mapping_entry(entry, _zp_raweth_mapping_array_get(array, idx)),
zp_free(s_mapping));
// Next iteration
idx += 1;
idx++;
entry = strtok(NULL, delim);

Check warning

Code scanning / Cppcheck (reported by Codacy)

strtok is MT-unsafe Warning

strtok is MT-unsafe
}
// Clean up
Expand All @@ -184,15 +184,15 @@ static const size_t _z_valid_whitelist_raweth(_z_str_intmap_t *config) {
strcpy(s_whitelist, cfg_str);
// Parse list
size_t size = 0;
char delim[] = {RAWETH_CFG_LIST_SEPARATOR};
const char *delim = RAWETH_CFG_LIST_SEPARATOR;
char *entry = strtok(s_whitelist, delim);

Check warning

Code scanning / Cppcheck (reported by Codacy)

strtok is MT-unsafe Warning

strtok is MT-unsafe
while (entry != NULL) {
// Check entry
if (!_z_valid_address_raweth(entry)) {
zp_free(s_whitelist);
return 0;
}
size += 1;
size++;
entry = strtok(NULL, delim);

Check warning

Code scanning / Cppcheck (reported by Codacy)

strtok is MT-unsafe Warning

strtok is MT-unsafe
}
// Parse last entry
Expand Down Expand Up @@ -221,7 +221,7 @@ static int8_t _z_get_whitelist_raweth(_z_str_intmap_t *config, _zp_raweth_whitel
}
size_t idx = 0;
// Parse list
char delim[] = {RAWETH_CFG_LIST_SEPARATOR};
const char *delim = RAWETH_CFG_LIST_SEPARATOR;
char *entry = strtok(s_whitelist, delim);

Check warning

Code scanning / Cppcheck (reported by Codacy)

strtok is MT-unsafe Warning

strtok is MT-unsafe
while ((entry != NULL) && (idx < _zp_raweth_whitelist_array_len(array))) {
// Convert address from string to int array
Expand All @@ -234,7 +234,7 @@ static int8_t _z_get_whitelist_raweth(_z_str_intmap_t *config, _zp_raweth_whitel
memcpy(elem->_mac, addr, _ZP_MAC_ADDR_LENGTH);
zp_free(addr);
// Next iteration
idx += 1;
idx++;
entry = strtok(NULL, delim);

Check warning

Code scanning / Cppcheck (reported by Codacy)

strtok is MT-unsafe Warning

strtok is MT-unsafe
}
// Clean up
Expand All @@ -244,12 +244,12 @@ static int8_t _z_get_whitelist_raweth(_z_str_intmap_t *config, _zp_raweth_whitel

static int8_t _z_get_mapping_entry(char *entry, _zp_raweth_mapping_entry_t *storage) {
size_t len = strlen(entry);
const char *entry_end = entry + (len - 1);
const char *entry_end = &entry[len - (size_t)1];

// Get first tuple member (keyexpr)
char *p_start = &entry[0];
char *p_end = strchr(p_start, RAWETH_CFG_TUPLE_SEPARATOR);
size_t ke_len = p_end - p_start;
size_t ke_len = (uintptr_t)p_end - (uintptr_t)p_start;
char *ke_suffix = (char *)zp_malloc(ke_len);
if (ke_suffix == NULL) {
return _Z_ERR_SYSTEM_OUT_OF_MEMORY;
Expand All @@ -258,7 +258,8 @@ static int8_t _z_get_mapping_entry(char *entry, _zp_raweth_mapping_entry_t *stor
storage->_keyexpr = _z_rid_with_suffix(Z_RESOURCE_ID_NONE, ke_suffix);

// Check second entry (address)
p_start = p_end + 1;
p_start = p_end;
p_start++;
p_end = strchr(p_start, RAWETH_CFG_TUPLE_SEPARATOR);
*p_end = '\0';
uint8_t *addr = _z_parse_address_raweth(p_start);
Expand All @@ -267,7 +268,8 @@ static int8_t _z_get_mapping_entry(char *entry, _zp_raweth_mapping_entry_t *stor
*p_end = RAWETH_CFG_TUPLE_SEPARATOR;

// Check optional third entry (vlan id)
p_start = p_end + 1;
p_start = p_end;
p_start++;
if (p_start >= entry_end) { // No entry
storage->_has_vlan = false;
} else {
Expand All @@ -278,15 +280,17 @@ static int8_t _z_get_mapping_entry(char *entry, _zp_raweth_mapping_entry_t *stor
}
static _Bool _z_valid_mapping_entry(char *entry) {
size_t len = strlen(entry);
const char *entry_end = entry + (len - 1);
const char *entry_end = &entry[len - (size_t)1];

// Check first tuple member (keyexpr)
char *p_start = &entry[0];
char *p_end = strchr(p_start, RAWETH_CFG_TUPLE_SEPARATOR);
if (p_end == NULL) {
return false;
}
// Check second entry (address)
p_start = p_end + 1;
p_start = p_end;
p_start++;
if (p_start > entry_end) {
return false;
}
Expand Down Expand Up @@ -374,7 +378,7 @@ static int8_t _z_f_link_open_raweth(_z_link_t *self) {
}
// Init socket mapping
size_t size = _z_valid_mapping_raweth(&self->_endpoint._config);
if (size != 0) {
if (size != (size_t)0) {
_Z_RETURN_IF_ERR(_z_get_mapping_raweth(&self->_endpoint._config, &self->_socket._raweth._mapping, size));
} else {
_Z_DEBUG("Invalid locator mapping, using default value.");
Expand All @@ -387,7 +391,7 @@ static int8_t _z_f_link_open_raweth(_z_link_t *self) {
}
// Init socket whitelist
size = _z_valid_whitelist_raweth(&self->_endpoint._config);
if (size != 0) {
if (size != (size_t)0) {
_Z_RETURN_IF_ERR(_z_get_whitelist_raweth(&self->_endpoint._config, &self->_socket._raweth._whitelist, size));
} else {
_Z_DEBUG("Invalid locator whitelist, filtering deactivated.");
Expand Down

0 comments on commit 30f0406

Please sign in to comment.