You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by gm...@apache.org on 2021/06/10 16:17:16 UTC
[qpid-dispatch] branch main updated: DISPATCH-2105: Removed
variable length arrays wherever possible. This closes #1249
This is an automated email from the ASF dual-hosted git repository.
gmurthy pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/qpid-dispatch.git
The following commit(s) were added to refs/heads/main by this push:
new 0c2a5d9 DISPATCH-2105: Removed variable length arrays wherever possible. This closes #1249
0c2a5d9 is described below
commit 0c2a5d9c2b0e6b716912101465cb661590d433b6
Author: Ganesh Murthy <gm...@apache.org>
AuthorDate: Tue Jun 8 16:09:27 2021 -0400
DISPATCH-2105: Removed variable length arrays wherever possible. This closes #1249
---
src/connection_manager.c | 6 +++---
src/log.c | 3 ++-
src/parse_tree.c | 9 +++++----
src/router_core/route_control.c | 3 ++-
src/router_node.c | 6 ++++--
5 files changed, 16 insertions(+), 11 deletions(-)
diff --git a/src/connection_manager.c b/src/connection_manager.c
index 601a6ac..a3838e0 100644
--- a/src/connection_manager.c
+++ b/src/connection_manager.c
@@ -801,9 +801,7 @@ qd_error_t qd_entity_refresh_connector(qd_entity_t* entity, void *impl)
int arr_length = get_failover_info_length(conn_info_list);
// This is the string that will contain the comma separated failover list
- char failover_info[arr_length + 1];
- failover_info[0] = 0;
-
+ char *failover_info = qd_calloc(arr_length + 1, sizeof(char));
while(item) {
// Break out of the loop when we have hit all items in the list.
@@ -875,10 +873,12 @@ qd_error_t qd_entity_refresh_connector(qd_entity_t* entity, void *impl)
&& qd_entity_set_string(entity, "connectionMsg", connector->conn_msg) == 0) {
sys_mutex_unlock(connector->lock);
+ free(failover_info);
return QD_ERROR_NONE;
}
sys_mutex_unlock(connector->lock);
+ free(failover_info);
return qd_error_code();
}
diff --git a/src/log.c b/src/log.c
index 28c45df..7030e05 100644
--- a/src/log.c
+++ b/src/log.c
@@ -272,7 +272,7 @@ static const char *SEPARATORS=", ;:";
/// Calculate the bit mask for a log enable string. Return -1 and set qd_error on error.
static int enable_mask(const char *enable_) {
- char enable[strlen(enable_)+1]; /* Non-const copy for strtok */
+ char *enable = qd_malloc(strlen(enable_) + 1);
strcpy(enable, enable_);
char *saveptr = 0;
int mask = 0;
@@ -285,6 +285,7 @@ static int enable_mask(const char *enable_) {
const level_t* level = level_for_name(token, len-plus);
mask |= (plus ? level->mask : level->bit);
}
+ free(enable);
return mask;
}
diff --git a/src/parse_tree.c b/src/parse_tree.c
index 1975c5e..e6d6b12 100644
--- a/src/parse_tree.c
+++ b/src/parse_tree.c
@@ -323,14 +323,15 @@ static qd_parse_node_t *new_parse_node(qd_parse_tree_t *tree,
n->token[tlen] = 0;
{
const size_t hkey_size = HKEY_PREFIX_LEN + tlen + 1;
- char hkey[hkey_size];
+ char *hkey = qd_malloc(hkey_size);
generate_hkey(hkey, hkey_size, parent->hkey_prefix, t);
if (qd_hash_insert_str(tree->hash, (unsigned char *)hkey, (void *)n, &n->handle) != QD_ERROR_NONE) {
free_parse_node(tree, n);
+ free(hkey);
return 0;
}
-
+ free(hkey);
n->parent = parent;
}
}
@@ -346,13 +347,13 @@ static qd_parse_node_t *parse_node_find_child(qd_parse_tree_t *tree, const qd_pa
qd_parse_node_t *child = 0;
const size_t tlen = TOKEN_LEN(*token);
const size_t hkey_size = HKEY_PREFIX_LEN + tlen + 1;
- char hkey[hkey_size];
-
+ char *hkey = qd_malloc(hkey_size);
generate_hkey(hkey, hkey_size, node->hkey_prefix, token);
qd_hash_retrieve_str(tree->hash, (const unsigned char *)hkey, (void **)&child);
if (child) {
assert(child->parent == node);
}
+ free(hkey);
return child;
}
diff --git a/src/router_core/route_control.c b/src/router_core/route_control.c
index 58b0114..7adfdc3 100644
--- a/src/router_core/route_control.c
+++ b/src/router_core/route_control.c
@@ -416,7 +416,7 @@ void qdr_route_auto_link_detached_CT(qdr_core_t *core, qdr_link_t *link)
int error_length = link->auto_link->last_error ? strlen(link->auto_link->last_error) : 0;
int total_length = strlen(activation_failed) + error_length + 1;
- char error_msg[total_length];
+ char *error_msg = qd_malloc(total_length);
strcpy(error_msg, activation_failed);
if (error_length)
strcat(error_msg, link->auto_link->last_error);
@@ -432,6 +432,7 @@ void qdr_route_auto_link_detached_CT(qdr_core_t *core, qdr_link_t *link)
}
qdr_route_log_CT(core, error_msg, link->auto_link->name, link->auto_link->identity, link->conn);
+ free(error_msg);
}
diff --git a/src/router_node.c b/src/router_node.c
index 6df6679..eea5be9 100644
--- a/src/router_node.c
+++ b/src/router_node.c
@@ -410,10 +410,11 @@ static void log_link_message(qd_connection_t *conn, pn_link_t *pn_link, qd_messa
if (!conn || !pn_link || !msg) return;
const qd_server_config_t *cf = qd_connection_config(conn);
if (!cf) return;
- char buf[qd_message_repr_len()];
+ size_t repr_len = qd_message_repr_len();
+ char *buf = qd_malloc(repr_len);
const char *msg_str = qd_message_oversize(msg) ? "oversize message" :
qd_message_aborted(msg) ? "aborted message" :
- qd_message_repr(msg, buf, sizeof(buf), cf->log_bits);
+ qd_message_repr(msg, buf, repr_len, cf->log_bits);
if (msg_str) {
const char *src = pn_terminus_get_address(pn_link_source(pn_link));
const char *tgt = pn_terminus_get_address(pn_link_target(pn_link));
@@ -426,6 +427,7 @@ static void log_link_message(qd_connection_t *conn, pn_link_t *pn_link, qd_messa
src ? src : "",
tgt ? tgt : "");
}
+ free(buf);
}
/**
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org