aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlonkaars <loek@pipeframe.xyz>2023-01-13 13:13:59 +0100
committerlonkaars <loek@pipeframe.xyz>2023-01-13 13:13:59 +0100
commite5d7490ff1b5f82879ff20e52c5ed10d2f7687fe (patch)
tree793ea32780b88186758f6037235005bc1ec517c2
parent85370ed5e33b3b28d01b6d49a22da4524e1b689f (diff)
replace use of `asprintf` with `snprintf`
-rw-r--r--confui/mesh_connector.cpp11
1 files changed, 6 insertions, 5 deletions
diff --git a/confui/mesh_connector.cpp b/confui/mesh_connector.cpp
index d6019cb..4479ff0 100644
--- a/confui/mesh_connector.cpp
+++ b/confui/mesh_connector.cpp
@@ -206,17 +206,18 @@ void CDMeshConnector::network_remove_node(cd_s_node *node_ptr) {
}
string CDMeshConnector::cd_mac_to_string(cd_mac_addr_t mac) {
- char *addr = nullptr;
- asprintf(&addr, "%02x:%02x:%02x:%02x:%02x:%02x", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
+ size_t str_s = sizeof("00:00:00:00:00:00");
+ char *addr = (char*) malloc(str_s);
+ snprintf(addr, str_s, "%02x:%02x:%02x:%02x:%02x:%02x", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
string ret = addr;
free(addr);
return ret;
}
string CDMeshConnector::cd_uuid_to_string(cd_uuid_t uuid) {
- char *addr = nullptr;
- asprintf(&addr, "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x", uuid[0], uuid[1], uuid[2], uuid[3], uuid[4], uuid[5], uuid[6], uuid[7], uuid[8],
- uuid[9], uuid[10], uuid[11], uuid[12], uuid[13], uuid[14], uuid[15]);
+ size_t str_s = sizeof("00000000-0000-0000-0000-000000000000");
+ char *addr = (char*) malloc(str_s);
+ snprintf(addr, str_s, "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x", uuid[0], uuid[1], uuid[2], uuid[3], uuid[4], uuid[5], uuid[6], uuid[7], uuid[8], uuid[9], uuid[10], uuid[11], uuid[12], uuid[13], uuid[14], uuid[15]);
string ret = addr;
free(addr);
return ret;