Skip to content

Commit

Permalink
fixup! Fix issues reported by clang-tidy
Browse files Browse the repository at this point in the history
  • Loading branch information
Danielius1922 committed Jun 24, 2023
1 parent 346cc02 commit 7f3b4a4
Show file tree
Hide file tree
Showing 18 changed files with 74 additions and 89 deletions.
5 changes: 2 additions & 3 deletions api/oc_discovery.c
Original file line number Diff line number Diff line change
Expand Up @@ -637,20 +637,19 @@ oc_core_1_1_discovery_handler(oc_request_t *request,
{
(void)data;
int matches = 0;
size_t device;

switch (iface_mask) {
case OC_IF_LL: {
oc_rep_start_links_array();
for (device = 0; device < oc_core_get_num_devices(); device++) {
for (size_t device = 0; device < oc_core_get_num_devices(); device++) {
matches += process_oic_1_1_device_object(oc_rep_array(links), request,
device, false);
}
oc_rep_end_links_array();
} break;
case OC_IF_BASELINE: {
oc_rep_start_links_array();
for (device = 0; device < oc_core_get_num_devices(); device++) {
for (size_t device = 0; device < oc_core_get_num_devices(); device++) {
matches += process_oic_1_1_device_object(oc_rep_array(links), request,
device, true);
}
Expand Down
3 changes: 1 addition & 2 deletions api/oc_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,7 @@ oc_get_block_size(void)
static void
oc_shutdown_all_devices(void)
{
size_t device;
for (device = 0; device < oc_core_get_num_devices(); device++) {
for (size_t device = 0; device < oc_core_get_num_devices(); device++) {
oc_connectivity_shutdown(device);
}

Expand Down
5 changes: 3 additions & 2 deletions api/oc_resource_factory.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,8 @@ oc_rt_factory_create_resource(oc_collection_t *collection,
}

void
oc_rt_factory_free_created_resource(oc_rt_created_t *rtc, oc_rt_factory_t *rf)
oc_rt_factory_free_created_resource(oc_rt_created_t *rtc,
const oc_rt_factory_t *rf)
{
if (oc_list_remove2(created_res, rtc) == NULL) {
/* protection against cyclical call of oc_rt_factory_free_created_resource
Expand All @@ -231,7 +232,7 @@ oc_fi_factory_free_all_created_resources(void)
}

oc_rt_created_t *
oc_rt_get_factory_create_for_resource(oc_resource_t *resource)
oc_rt_get_factory_create_for_resource(const oc_resource_t *resource)
{
oc_rt_created_t *rtc = (oc_rt_created_t *)oc_list_head(created_res);
while (rtc) {
Expand Down
5 changes: 3 additions & 2 deletions api/oc_resource_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,12 @@ oc_rt_created_t *oc_rt_factory_create_resource(oc_collection_t *collection,
size_t device);

void oc_rt_factory_free_created_resource(oc_rt_created_t *rtc,
oc_rt_factory_t *rf);
const oc_rt_factory_t *rf);

void oc_rt_factory_free_created_resources(size_t device);

oc_rt_created_t *oc_rt_get_factory_create_for_resource(oc_resource_t *resource);
oc_rt_created_t *oc_rt_get_factory_create_for_resource(
const oc_resource_t *resource);

void oc_fi_factory_free_all_created_resources(void);

Expand Down
7 changes: 3 additions & 4 deletions api/oc_server_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ oc_reset_delayed_callback_ms(void *cb_data, oc_trigger_t callback,
}

bool
oc_has_delayed_callback(void *cb_data, oc_trigger_t callback,
oc_has_delayed_callback(const void *cb_data, oc_trigger_t callback,
bool ignore_cb_data)
{
return oc_ri_has_timed_event_callback(cb_data, callback, ignore_cb_data);
Expand All @@ -242,7 +242,7 @@ oc_remove_delayed_callback_by_filter(oc_trigger_t cb,
}

void
oc_remove_delayed_callback(void *cb_data, oc_trigger_t callback)
oc_remove_delayed_callback(const void *cb_data, oc_trigger_t callback)
{
oc_ri_remove_timed_event_callback(cb_data, callback);
}
Expand Down Expand Up @@ -653,8 +653,7 @@ oc_resource_set_secure_mcast(oc_resource_t *resource, bool supported)
void
oc_set_con_write_cb(oc_con_write_cb_t callback)
{
size_t i;
for (i = 0; i < oc_core_get_num_devices(); i++) {
for (size_t i = 0; i < oc_core_get_num_devices(); i++) {
oc_resource_t *res = oc_core_get_resource_by_index(OCF_CON, i);
if (res) {
res->post_handler.user_data = *(void **)(&callback);
Expand Down
9 changes: 4 additions & 5 deletions apps/client_collections_linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,14 @@ post_lights_oic_if_create(oc_client_response_t *data)
case OC_REP_STRING:
OC_PRINTF("%s\n\n", oc_string(rep->value.string));
break;
case OC_REP_STRING_ARRAY: {
size_t i;
for (i = 0; i < oc_string_array_get_allocated_size(rep->value.array);
i++) {
case OC_REP_STRING_ARRAY:
for (size_t i = 0;
i < oc_string_array_get_allocated_size(rep->value.array); i++) {

OC_PRINTF(" %s ", oc_string_array_get_item(rep->value.array, i));
}
OC_PRINTF("\n");
} break;
break;
case OC_REP_INT:
OC_PRINTF(" %" PRId64 "\n", rep->value.integer);
break;
Expand Down
59 changes: 30 additions & 29 deletions apps/cloud_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -606,35 +606,36 @@ get_switch_instance(const char *href, oc_string_array_t *types,
size_t device)
{
oc_switch_t *cswitch = (oc_switch_t *)oc_memb_alloc(&switch_s);
if (cswitch) {
cswitch->resource = oc_new_resource(
NULL, href, oc_string_array_get_allocated_size(*types), device);
if (cswitch->resource) {
size_t i;
for (i = 0; i < oc_string_array_get_allocated_size(*types); i++) {
const char *rt = oc_string_array_get_item(*types, i);
oc_resource_bind_resource_type(cswitch->resource, rt);
}
oc_resource_bind_resource_interface(cswitch->resource, iface_mask);
cswitch->resource->properties = bm;
oc_resource_set_default_interface(cswitch->resource, OC_IF_A);
oc_resource_set_request_handler(cswitch->resource, OC_GET, get_cswitch,
cswitch);
oc_resource_set_request_handler(cswitch->resource, OC_DELETE,
delete_cswitch, cswitch);
oc_resource_set_request_handler(cswitch->resource, OC_POST, post_cswitch,
cswitch);
oc_resource_set_properties_cbs(cswitch->resource, get_switch_properties,
cswitch, set_switch_properties, cswitch);
oc_add_resource(cswitch->resource);
oc_set_delayed_callback(cswitch->resource, register_to_cloud, 0);
oc_list_add(switches, cswitch);
return cswitch->resource;
} else {
oc_memb_free(&switch_s, cswitch);
}
}
return NULL;
if (cswitch == NULL) {
printf("ERROR: insufficient memory to add new switch instance");
return NULL;
}
cswitch->resource = oc_new_resource(
NULL, href, oc_string_array_get_allocated_size(*types), device);
if (cswitch->resource == NULL) {
printf("ERROR: could not create /switch instance");
oc_memb_free(&switch_s, cswitch);
return NULL;
}
for (size_t i = 0; i < oc_string_array_get_allocated_size(*types); i++) {
const char *rt = oc_string_array_get_item(*types, i);
oc_resource_bind_resource_type(cswitch->resource, rt);
}
oc_resource_bind_resource_interface(cswitch->resource, iface_mask);
cswitch->resource->properties = bm;
oc_resource_set_default_interface(cswitch->resource, OC_IF_A);
oc_resource_set_request_handler(cswitch->resource, OC_GET, get_cswitch,
cswitch);
oc_resource_set_request_handler(cswitch->resource, OC_DELETE, delete_cswitch,
cswitch);
oc_resource_set_request_handler(cswitch->resource, OC_POST, post_cswitch,
cswitch);
oc_resource_set_properties_cbs(cswitch->resource, get_switch_properties,
cswitch, set_switch_properties, cswitch);
oc_add_resource(cswitch->resource);
oc_set_delayed_callback(cswitch->resource, register_to_cloud, 0);
oc_list_add(switches, cswitch);
return cswitch->resource;
}

static void
Expand Down
4 changes: 2 additions & 2 deletions include/oc_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -2645,7 +2645,7 @@ void oc_set_delayed_callback_ms_v1(void *cb_data, oc_trigger_t callback,
* @return false otherwise
*/
OC_API
bool oc_has_delayed_callback(void *cb_data, oc_trigger_t callback,
bool oc_has_delayed_callback(const void *cb_data, oc_trigger_t callback,
bool ignore_cb_data);

/**
Expand Down Expand Up @@ -2681,7 +2681,7 @@ void oc_remove_delayed_callback_by_filter(
* @param[in] callback the delayed callback that is being removed
*/
OC_API
void oc_remove_delayed_callback(void *cb_data, oc_trigger_t callback);
void oc_remove_delayed_callback(const void *cb_data, oc_trigger_t callback);

/** API for setting handlers for interrupts */

Expand Down
3 changes: 1 addition & 2 deletions messaging/coap/engine.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,7 @@ static uint8_t g_idx = 0;
bool
oc_coap_check_if_duplicate(uint16_t mid, uint32_t device)
{
size_t i;
for (i = 0; i < OC_REQUEST_HISTORY_SIZE; i++) {
for (size_t i = 0; i < OC_REQUEST_HISTORY_SIZE; i++) {
if (g_history[i] == mid && g_history_dev[i] == device) {
OC_DBG("dropping duplicate request");
return true;
Expand Down
4 changes: 2 additions & 2 deletions messaging/coap/oscore.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ oscore_read_piv(const uint8_t *piv, uint8_t piv_len, uint64_t *ssn)
{
*ssn = 0;

uint8_t i, j = sizeof(uint64_t) - piv_len;
for (i = 0; i < piv_len; i++, j++) {
uint8_t j = sizeof(uint64_t) - piv_len;
for (uint8_t i = 0; i < piv_len; i++, j++) {
memcpy((char *)ssn + j, &piv[i], 1);
}

Expand Down
24 changes: 10 additions & 14 deletions messaging/coap/transactions.c
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,9 @@ coap_clear_transaction(coap_transaction_t *t)
coap_transaction_t *
coap_get_transaction_by_mid(uint16_t mid)
{
coap_transaction_t *t = NULL;

for (t = (coap_transaction_t *)oc_list_head(transactions_list); t;
t = t->next) {
for (coap_transaction_t *t =
(coap_transaction_t *)oc_list_head(transactions_list);
t != NULL; t = t->next) {
if (t->mid == mid) {
OC_DBG("Found transaction for MID %u: %p", t->mid, (void *)t);
return t;
Expand All @@ -226,10 +225,9 @@ coap_get_transaction_by_mid(uint16_t mid)
coap_transaction_t *
coap_get_transaction_by_token(uint8_t *token, uint8_t token_len)
{
coap_transaction_t *t = NULL;

for (t = (coap_transaction_t *)oc_list_head(transactions_list); t;
t = t->next) {
for (coap_transaction_t *t =
(coap_transaction_t *)oc_list_head(transactions_list);
t != NULL; t = t->next) {
if (t->token_len == token_len && memcmp(t->token, token, token_len) == 0) {
OC_DBG("Found transaction by token %p", (void *)t);
return t;
Expand All @@ -241,10 +239,9 @@ coap_get_transaction_by_token(uint8_t *token, uint8_t token_len)
void
coap_check_transactions(void)
{
coap_transaction_t *t = (coap_transaction_t *)oc_list_head(transactions_list),
*next;
coap_transaction_t *t = (coap_transaction_t *)oc_list_head(transactions_list);
while (t != NULL) {
next = t->next;
coap_transaction_t *next = t->next;
if (oc_etimer_expired(&t->retrans_timer)) {
++(t->retrans_counter);
OC_DBG("Retransmitting %u (%u)", t->mid, t->retrans_counter);
Expand All @@ -262,10 +259,9 @@ coap_check_transactions(void)
void
coap_free_all_transactions(void)
{
coap_transaction_t *t = (coap_transaction_t *)oc_list_head(transactions_list),
*next;
coap_transaction_t *t = (coap_transaction_t *)oc_list_head(transactions_list);
while (t != NULL) {
next = t->next;
coap_transaction_t *next = t->next;
coap_clear_transaction(t);
t = next;
}
Expand Down
5 changes: 3 additions & 2 deletions port/linux/ipadapter.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,13 @@ add_ip_interface(int target_index)
static bool
check_new_ip_interfaces(void)
{
struct ifaddrs *ifs = NULL, *interface = NULL;
struct ifaddrs *ifs = NULL;
if (getifaddrs(&ifs) < 0) {
OC_ERR("querying interface address");
return false;
}
for (interface = ifs; interface != NULL; interface = interface->ifa_next) {
for (struct ifaddrs *interface = ifs; interface != NULL;
interface = interface->ifa_next) {
/* Ignore interfaces that are down and the loopback interface */
if (!(interface->ifa_flags & IFF_UP) ||
(interface->ifa_flags & IFF_LOOPBACK)) {
Expand Down
9 changes: 3 additions & 6 deletions security/oc_ael.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,17 +122,15 @@ oc_sec_ael_init(void)
oc_abort("Insufficient memory");
}
#endif /* OC_DYNAMIC_ALLOCATION */
size_t device;
for (device = 0; device < oc_core_get_num_devices(); device++) {
for (size_t device = 0; device < oc_core_get_num_devices(); device++) {
OC_LIST_STRUCT_INIT(&ael[device], events);
}
}

void
oc_sec_ael_free(void)
{
size_t device;
for (device = 0; device < oc_core_get_num_devices(); device++) {
for (size_t device = 0; device < oc_core_get_num_devices(); device++) {
oc_sec_ael_reset(device);
}
#ifdef OC_DYNAMIC_ALLOCATION
Expand Down Expand Up @@ -492,8 +490,7 @@ oc_sec_ael_create_event(size_t device, uint8_t category, uint8_t priority,
oc_new_string(&res->message, message, strlen(message));
}
if (aux_info && aux_size > 0) {
size_t i;
for (i = 0; i < aux_size; i++) {
for (size_t i = 0; i < aux_size; i++) {
oc_sec_ael_aux_info_t *a_info =
(oc_sec_ael_aux_info_t *)oc_memb_alloc(&aux_s);
if (a_info) {
Expand Down
9 changes: 3 additions & 6 deletions security/oc_cred.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,7 @@ oc_sec_cred_init(void)
oc_abort("Insufficient memory");
}
#endif /* OC_DYNAMIC_ALLOCATION */
size_t i;
for (i = 0; i < oc_core_get_num_devices(); i++) {
for (size_t i = 0; i < oc_core_get_num_devices(); i++) {
OC_LIST_STRUCT_INIT(&devices[i], creds);
}
}
Expand Down Expand Up @@ -319,8 +318,7 @@ oc_sec_cred_default(size_t device)
void
oc_sec_cred_free(void)
{
size_t device;
for (device = 0; device < oc_core_get_num_devices(); device++) {
for (size_t device = 0; device < oc_core_get_num_devices(); device++) {
oc_sec_cred_clear(device, NULL, NULL);
}
#ifdef OC_DYNAMIC_ALLOCATION
Expand Down Expand Up @@ -1248,8 +1246,7 @@ is_valid_oscore_id(const char *id, size_t id_len)
if (id_len != 14) {
return false;
}
size_t i;
for (i = 0; i < id_len; i++) {
for (size_t i = 0; i < id_len; i++) {
if (!isxdigit(id[i])) {
return false;
}
Expand Down
3 changes: 1 addition & 2 deletions security/oc_oscore_engine.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,11 @@ dump_cred(void *data)
static bool
check_if_replayed_request(oc_oscore_context_t *oscore_ctx, uint64_t piv)
{
uint8_t i;
if (piv == 0 && oscore_ctx->rwin[0] == 0 &&
oscore_ctx->rwin[OSCORE_REPLAY_WINDOW_SIZE - 1] == 0) {
goto fresh_request;
}
for (i = 0; i < OSCORE_REPLAY_WINDOW_SIZE; i++) {
for (uint8_t i = 0; i < OSCORE_REPLAY_WINDOW_SIZE; i++) {
if (oscore_ctx->rwin[i] == piv) {
return true;
}
Expand Down
3 changes: 1 addition & 2 deletions security/oc_pstat.c
Original file line number Diff line number Diff line change
Expand Up @@ -675,8 +675,7 @@ oc_reset_device_v1(size_t device, bool close_all_tls_connections_immediately)
void
oc_reset_v1(bool close_all_tls_connections_immediately)
{
size_t device;
for (device = 0; device < oc_core_get_num_devices(); device++) {
for (size_t device = 0; device < oc_core_get_num_devices(); device++) {
oc_reset_device_v1(device, close_all_tls_connections_immediately);
}
}
Expand Down
3 changes: 1 addition & 2 deletions security/oc_tls.c
Original file line number Diff line number Diff line change
Expand Up @@ -830,8 +830,7 @@ oc_tls_add_new_certs(oc_sec_credusage_t credusage,
check_if_known_cert_cb is_known_cert,
add_new_cert_cb add_new_cert)
{
size_t device;
for (device = 0; device < oc_core_get_num_devices(); device++) {
for (size_t device = 0; device < oc_core_get_num_devices(); device++) {
oc_sec_creds_t *creds = oc_sec_get_creds(device);
oc_sec_cred_t *cred = (oc_sec_cred_t *)oc_list_head(creds->creds);
for (; cred != NULL; cred = cred->next) {
Expand Down
3 changes: 1 addition & 2 deletions security/unittest/tls_cert_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,7 @@ TEST_F(TestTlsCertificates, RemoveTrustAnchors)

TEST_F(TestTlsCertificates, VerifyCredCerts)
{
auto verify_cert_validity = [](const oc_sec_certs_data_t *data,
void *) -> bool {
auto verify_cert_validity = [](const oc_sec_certs_data_t *data, void *) {
return (time_t)data->valid_from <= TestTlsCertificates::now_ &&
(time_t)data->valid_to > TestTlsCertificates::now_;
};
Expand Down

0 comments on commit 7f3b4a4

Please sign in to comment.