Skip to content

Commit

Permalink
Merge branch 'fix_strtol' into 'main'
Browse files Browse the repository at this point in the history
Replace strtol with strtoul wherever required

See merge request app-frameworks/esp-matter!528
  • Loading branch information
dhrishi committed Nov 3, 2023
2 parents c45ce10 + 71379cc commit 198db12
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 40 deletions.
12 changes: 6 additions & 6 deletions components/esp_matter/esp_matter_attribute_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -515,9 +515,9 @@ static esp_err_t console_set_handler(int argc, char **argv)
return ESP_ERR_INVALID_ARG;
}

uint16_t endpoint_id = strtol((const char *)&argv[0][2], NULL, 16);
uint32_t cluster_id = strtol((const char *)&argv[1][2], NULL, 16);
uint32_t attribute_id = strtol((const char *)&argv[2][2], NULL, 16);
uint16_t endpoint_id = strtoul((const char *)&argv[0][2], NULL, 16);
uint32_t cluster_id = strtoul((const char *)&argv[1][2], NULL, 16);
uint32_t attribute_id = strtoul((const char *)&argv[2][2], NULL, 16);

/* Get type from matter_attribute */
const EmberAfAttributeMetadata *matter_attribute = emberAfLocateAttributeMetadata(endpoint_id, cluster_id,
Expand Down Expand Up @@ -708,9 +708,9 @@ static esp_err_t console_get_handler(int argc, char **argv)
ESP_LOGE(TAG, "The arguments for this command is invalid");
return ESP_ERR_INVALID_ARG;
}
uint16_t endpoint_id = strtol((const char *)&argv[0][2], NULL, 16);
uint32_t cluster_id = strtol((const char *)&argv[1][2], NULL, 16);
uint32_t attribute_id = strtol((const char *)&argv[2][2], NULL, 16);
uint16_t endpoint_id = strtoul((const char *)&argv[0][2], NULL, 16);
uint32_t cluster_id = strtoul((const char *)&argv[1][2], NULL, 16);
uint32_t attribute_id = strtoul((const char *)&argv[2][2], NULL, 16);

/* Get type from matter_attribute */
const EmberAfAttributeMetadata *matter_attribute = emberAfLocateAttributeMetadata(endpoint_id, cluster_id,
Expand Down
34 changes: 17 additions & 17 deletions examples/esp-now_bridge_light/main/app_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ static esp_err_t app_driver_bound_console_handler(int argc, char **argv)
"\t\tExample: matter esp bound invoke-group 0x0001 0x0008 0x0000 0x50 0x0 0x1 0x1.\n");
} else if (argc >= 4 && strncmp(argv[0], "invoke", sizeof("invoke")) == 0) {
client::command_handle_t cmd_handle;
uint16_t local_endpoint_id = strtol((const char *)&argv[1][2], NULL, 16);
cmd_handle.cluster_id = strtol((const char *)&argv[2][2], NULL, 16);
cmd_handle.command_id = strtol((const char *)&argv[3][2], NULL, 16);
uint16_t local_endpoint_id = strtoul((const char *)&argv[1][2], NULL, 16);
cmd_handle.cluster_id = strtoul((const char *)&argv[2][2], NULL, 16);
cmd_handle.command_id = strtoul((const char *)&argv[3][2], NULL, 16);
cmd_handle.is_group = false;

if (argc > 4) {
Expand All @@ -58,9 +58,9 @@ static esp_err_t app_driver_bound_console_handler(int argc, char **argv)
client::cluster_update(local_endpoint_id, &cmd_handle);
} else if (argc >= 4 && strncmp(argv[0], "invoke-group", sizeof("invoke-group")) == 0) {
client::command_handle_t cmd_handle;
uint16_t local_endpoint_id = strtol((const char *)&argv[1][2], NULL, 16);
cmd_handle.cluster_id = strtol((const char *)&argv[2][2], NULL, 16);
cmd_handle.command_id = strtol((const char *)&argv[3][2], NULL, 16);
uint16_t local_endpoint_id = strtoul((const char *)&argv[1][2], NULL, 16);
cmd_handle.cluster_id = strtoul((const char *)&argv[2][2], NULL, 16);
cmd_handle.command_id = strtoul((const char *)&argv[3][2], NULL, 16);
cmd_handle.is_group = true;

if (argc > 4) {
Expand Down Expand Up @@ -99,11 +99,11 @@ static esp_err_t app_driver_client_console_handler(int argc, char **argv)
"\t\tExample: matter esp client invoke-group 0x0001 0x257 0x0008 0x0000 0x50 0x0 0x1 0x1.\n");
} else if (argc >= 6 && strncmp(argv[0], "invoke", sizeof("invoke")) == 0) {
client::command_handle_t cmd_handle;
uint8_t fabric_index = strtol((const char *)&argv[1][2], NULL, 16);
uint64_t node_id = strtol((const char *)&argv[2][2], NULL, 16);
cmd_handle.endpoint_id = strtol((const char *)&argv[3][2], NULL, 16);
cmd_handle.cluster_id = strtol((const char *)&argv[4][2], NULL, 16);
cmd_handle.command_id = strtol((const char *)&argv[5][2], NULL, 16);
uint8_t fabric_index = strtoul((const char *)&argv[1][2], NULL, 16);
uint64_t node_id = strtoull((const char *)&argv[2][2], NULL, 16);
cmd_handle.endpoint_id = strtoul((const char *)&argv[3][2], NULL, 16);
cmd_handle.cluster_id = strtoul((const char *)&argv[4][2], NULL, 16);
cmd_handle.command_id = strtoul((const char *)&argv[5][2], NULL, 16);
cmd_handle.is_group = false;

if (argc > 6) {
Expand All @@ -122,10 +122,10 @@ static esp_err_t app_driver_client_console_handler(int argc, char **argv)
client::connect(fabric_index, node_id, &cmd_handle);
} else if (argc >= 5 && strncmp(argv[0], "invoke-group", sizeof("invoke-group")) == 0) {
client::command_handle_t cmd_handle;
uint8_t fabric_index = strtol((const char *)&argv[1][2], NULL, 16);
cmd_handle.group_id = strtol((const char *)&argv[2][2], NULL, 16);
cmd_handle.cluster_id = strtol((const char *)&argv[3][2], NULL, 16);
cmd_handle.command_id = strtol((const char *)&argv[4][2], NULL, 16);
uint8_t fabric_index = strtoul((const char *)&argv[1][2], NULL, 16);
cmd_handle.group_id = strtoul((const char *)&argv[2][2], NULL, 16);
cmd_handle.cluster_id = strtoul((const char *)&argv[3][2], NULL, 16);
cmd_handle.command_id = strtoul((const char *)&argv[4][2], NULL, 16);
cmd_handle.is_group = true;

if (argc > 5) {
Expand Down Expand Up @@ -206,7 +206,7 @@ void app_driver_client_command_callback(client::peer_device_t *peer_device, clie
return;
}
identify::command::send_identify(peer_device, cmd_handle->endpoint_id,
strtol((const char *)(cmd_handle->command_data) + 1, NULL, 16));
strtoul((const char *)(cmd_handle->command_data) + 1, NULL, 16));
} else {
ESP_LOGE(TAG, "Unsupported command");
}
Expand Down Expand Up @@ -244,7 +244,7 @@ void app_driver_client_group_command_callback(uint8_t fabric_index, client::comm
return;
}
identify::command::group_send_identify(fabric_index, cmd_handle->group_id,
strtol((const char *)(cmd_handle->command_data) + 1, NULL, 16));
strtoul((const char *)(cmd_handle->command_data) + 1, NULL, 16));
} else {
ESP_LOGE(TAG, "Unsupported command");
}
Expand Down
34 changes: 17 additions & 17 deletions examples/light_switch/main/app_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ static esp_err_t app_driver_bound_console_handler(int argc, char **argv)
"\t\tExample: matter esp bound invoke-group 0x0001 0x0003 0x0000 0x78.\n");
} else if (argc >= 4 && strncmp(argv[0], "invoke", sizeof("invoke")) == 0) {
client::command_handle_t cmd_handle;
uint16_t local_endpoint_id = strtol((const char *)&argv[1][2], NULL, 16);
cmd_handle.cluster_id = strtol((const char *)&argv[2][2], NULL, 16);
cmd_handle.command_id = strtol((const char *)&argv[3][2], NULL, 16);
uint16_t local_endpoint_id = strtoul((const char *)&argv[1][2], NULL, 16);
cmd_handle.cluster_id = strtoul((const char *)&argv[2][2], NULL, 16);
cmd_handle.command_id = strtoul((const char *)&argv[3][2], NULL, 16);
cmd_handle.is_group = false;

if (argc > 4) {
Expand All @@ -63,9 +63,9 @@ static esp_err_t app_driver_bound_console_handler(int argc, char **argv)
client::cluster_update(local_endpoint_id, &cmd_handle);
} else if (argc >= 4 && strncmp(argv[0], "invoke-group", sizeof("invoke-group")) == 0) {
client::command_handle_t cmd_handle;
uint16_t local_endpoint_id = strtol((const char *)&argv[1][2], NULL, 16);
cmd_handle.cluster_id = strtol((const char *)&argv[2][2], NULL, 16);
cmd_handle.command_id = strtol((const char *)&argv[3][2], NULL, 16);
uint16_t local_endpoint_id = strtoul((const char *)&argv[1][2], NULL, 16);
cmd_handle.cluster_id = strtoul((const char *)&argv[2][2], NULL, 16);
cmd_handle.command_id = strtoul((const char *)&argv[3][2], NULL, 16);
cmd_handle.is_group = true;

if (argc > 4) {
Expand Down Expand Up @@ -103,11 +103,11 @@ static esp_err_t app_driver_client_console_handler(int argc, char **argv)
"\t\tExample: matter esp client invoke-group 0x0001 0x257 0x0003 0x0000 0x78.\n");
} else if (argc >= 6 && strncmp(argv[0], "invoke", sizeof("invoke")) == 0) {
client::command_handle_t cmd_handle;
uint8_t fabric_index = strtol((const char *)&argv[1][2], NULL, 16);
uint64_t node_id = strtol((const char *)&argv[2][2], NULL, 16);
cmd_handle.endpoint_id = strtol((const char *)&argv[3][2], NULL, 16);
cmd_handle.cluster_id = strtol((const char *)&argv[4][2], NULL, 16);
cmd_handle.command_id = strtol((const char *)&argv[5][2], NULL, 16);
uint8_t fabric_index = strtoul((const char *)&argv[1][2], NULL, 16);
uint64_t node_id = strtoull((const char *)&argv[2][2], NULL, 16);
cmd_handle.endpoint_id = strtoul((const char *)&argv[3][2], NULL, 16);
cmd_handle.cluster_id = strtoul((const char *)&argv[4][2], NULL, 16);
cmd_handle.command_id = strtoul((const char *)&argv[5][2], NULL, 16);
cmd_handle.is_group = false;

if (argc > 6) {
Expand All @@ -127,10 +127,10 @@ static esp_err_t app_driver_client_console_handler(int argc, char **argv)
client::connect(fabric_index, node_id, &cmd_handle);
} else if (argc >= 5 && strncmp(argv[0], "invoke-group", sizeof("invoke-group")) == 0) {
client::command_handle_t cmd_handle;
uint8_t fabric_index = strtol((const char *)&argv[1][2], NULL, 16);
cmd_handle.group_id = strtol((const char *)&argv[2][2], NULL, 16);
cmd_handle.cluster_id = strtol((const char *)&argv[3][2], NULL, 16);
cmd_handle.command_id = strtol((const char *)&argv[4][2], NULL, 16);
uint8_t fabric_index = strtoul((const char *)&argv[1][2], NULL, 16);
cmd_handle.group_id = strtoul((const char *)&argv[2][2], NULL, 16);
cmd_handle.cluster_id = strtoul((const char *)&argv[3][2], NULL, 16);
cmd_handle.command_id = strtoul((const char *)&argv[4][2], NULL, 16);
cmd_handle.is_group = true;

if (argc > 5) {
Expand Down Expand Up @@ -208,7 +208,7 @@ void app_driver_client_command_callback(client::peer_device_t *peer_device, clie
return;
}
identify::command::send_identify(peer_device, cmd_handle->endpoint_id,
strtol((const char *)(cmd_handle->command_data) + 1, NULL, 16));
strtoul((const char *)(cmd_handle->command_data) + 1, NULL, 16));
} else {
ESP_LOGE(TAG, "Unsupported command");
}
Expand Down Expand Up @@ -245,7 +245,7 @@ void app_driver_client_group_command_callback(uint8_t fabric_index, client::comm
return;
}
identify::command::group_send_identify(fabric_index, cmd_handle->group_id,
strtol((const char *)(cmd_handle->command_data) + 1, NULL, 16));
strtoul((const char *)(cmd_handle->command_data) + 1, NULL, 16));
} else {
ESP_LOGE(TAG, "Unsupported command");
}
Expand Down

0 comments on commit 198db12

Please sign in to comment.