summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDonald Sharp <sharpd@nvidia.com>2021-07-12 19:32:42 -0400
committerDonald Sharp <sharpd@nvidia.com>2021-07-12 19:32:42 -0400
commit0b04fa0e78eef6b458b0ab40a9473691cd56b64c (patch)
treea589cf80a267ab2266670af91344e735584054de
parent507559a089a7ba539b90c4bb1cd0410a4b4b1345 (diff)
bgpd: XREALLOC handles NULL properly
the realloc man page: If ptr is NULL, then the call is equivalent to malloc(size) This should be sufficient for our needs to not have to have XMALLOC and XREALLOC Signed-off-by: Donald Sharp <sharpd@nvidia.com>
-rw-r--r--bgpd/bgp_attr.c7
-rw-r--r--bgpd/bgp_community.c15
-rw-r--r--bgpd/bgp_ecommunity.c12
-rw-r--r--bgpd/bgp_lcommunity.c8
-rw-r--r--bgpd/bgpd.c11
5 files changed, 13 insertions, 40 deletions
diff --git a/bgpd/bgp_attr.c b/bgpd/bgp_attr.c
index 24b48178d2..adf408220e 100644
--- a/bgpd/bgp_attr.c
+++ b/bgpd/bgp_attr.c
@@ -2915,11 +2915,8 @@ static bgp_attr_parse_ret_t bgp_attr_unknown(struct bgp_attr_parser_args *args)
if (!transit)
transit = XCALLOC(MTYPE_TRANSIT, sizeof(struct transit));
- if (transit->val)
- transit->val = XREALLOC(MTYPE_TRANSIT_VAL, transit->val,
- transit->length + total);
- else
- transit->val = XMALLOC(MTYPE_TRANSIT_VAL, total);
+ transit->val = XREALLOC(MTYPE_TRANSIT_VAL, transit->val,
+ transit->length + total);
memcpy(transit->val + transit->length, startp, total);
transit->length += total;
diff --git a/bgpd/bgp_community.c b/bgpd/bgp_community.c
index 2aa6a56a5e..e91166449a 100644
--- a/bgpd/bgp_community.c
+++ b/bgpd/bgp_community.c
@@ -60,11 +60,7 @@ void community_free(struct community **com)
void community_add_val(struct community *com, uint32_t val)
{
com->size++;
- if (com->val)
- com->val = XREALLOC(MTYPE_COMMUNITY_VAL, com->val,
- com_length(com));
- else
- com->val = XMALLOC(MTYPE_COMMUNITY_VAL, com_length(com));
+ com->val = XREALLOC(MTYPE_COMMUNITY_VAL, com->val, com_length(com));
val = htonl(val);
memcpy(com_lastval(com), &val, sizeof(uint32_t));
@@ -618,13 +614,8 @@ bool community_cmp(const struct community *com1, const struct community *com2)
struct community *community_merge(struct community *com1,
struct community *com2)
{
- if (com1->val)
- com1->val =
- XREALLOC(MTYPE_COMMUNITY_VAL, com1->val,
- (com1->size + com2->size) * COMMUNITY_SIZE);
- else
- com1->val = XMALLOC(MTYPE_COMMUNITY_VAL,
- (com1->size + com2->size) * COMMUNITY_SIZE);
+ com1->val = XREALLOC(MTYPE_COMMUNITY_VAL, com1->val,
+ (com1->size + com2->size) * COMMUNITY_SIZE);
memcpy(com1->val + com1->size, com2->val, com2->size * COMMUNITY_SIZE);
com1->size += com2->size;
diff --git a/bgpd/bgp_ecommunity.c b/bgpd/bgp_ecommunity.c
index 923c9b0d7e..3a951e6e80 100644
--- a/bgpd/bgp_ecommunity.c
+++ b/bgpd/bgp_ecommunity.c
@@ -158,7 +158,6 @@ static bool ecommunity_add_val_internal(struct ecommunity *ecom,
ecom->val = XREALLOC(MTYPE_ECOMMUNITY_VAL, ecom->val,
ecom_length_size(ecom, ecom_size));
-
memmove(ecom->val + ((ins_idx + 1) * ecom_size),
ecom->val + (ins_idx * ecom_size),
(ecom->size - 1 - ins_idx) * ecom_size);
@@ -287,14 +286,9 @@ char *ecommunity_str(struct ecommunity *ecom)
struct ecommunity *ecommunity_merge(struct ecommunity *ecom1,
struct ecommunity *ecom2)
{
- if (ecom1->val)
- ecom1->val = XREALLOC(MTYPE_ECOMMUNITY_VAL, ecom1->val,
- (size_t)(ecom1->size + ecom2->size)
- * (size_t)ecom1->unit_size);
- else
- ecom1->val = XMALLOC(MTYPE_ECOMMUNITY_VAL,
- (size_t)(ecom1->size + ecom2->size)
- * (size_t)ecom1->unit_size);
+ ecom1->val = XREALLOC(MTYPE_ECOMMUNITY_VAL, ecom1->val,
+ (size_t)(ecom1->size + ecom2->size)
+ * (size_t)ecom1->unit_size);
memcpy(ecom1->val + (ecom1->size * ecom1->unit_size), ecom2->val,
(size_t)ecom2->size * (size_t)ecom1->unit_size);
diff --git a/bgpd/bgp_lcommunity.c b/bgpd/bgp_lcommunity.c
index fa4d4aee28..6121c4905f 100644
--- a/bgpd/bgp_lcommunity.c
+++ b/bgpd/bgp_lcommunity.c
@@ -166,12 +166,8 @@ struct lcommunity *lcommunity_dup(struct lcommunity *lcom)
struct lcommunity *lcommunity_merge(struct lcommunity *lcom1,
struct lcommunity *lcom2)
{
- if (lcom1->val)
- lcom1->val = XREALLOC(MTYPE_LCOMMUNITY_VAL, lcom1->val,
- lcom_length(lcom1) + lcom_length(lcom2));
- else
- lcom1->val = XMALLOC(MTYPE_LCOMMUNITY_VAL,
- lcom_length(lcom1) + lcom_length(lcom2));
+ lcom1->val = XREALLOC(MTYPE_LCOMMUNITY_VAL, lcom1->val,
+ lcom_length(lcom1) + lcom_length(lcom2));
memcpy(lcom1->val + lcom_length(lcom1), lcom2->val, lcom_length(lcom2));
lcom1->size += lcom2->size;
diff --git a/bgpd/bgpd.c b/bgpd/bgpd.c
index acade16ef2..89acf9cad2 100644
--- a/bgpd/bgpd.c
+++ b/bgpd/bgpd.c
@@ -656,14 +656,9 @@ int bgp_confederation_peers_add(struct bgp *bgp, as_t as)
if (bgp_confederation_peers_check(bgp, as))
return -1;
- if (bgp->confed_peers)
- bgp->confed_peers =
- XREALLOC(MTYPE_BGP_CONFED_LIST, bgp->confed_peers,
- (bgp->confed_peers_cnt + 1) * sizeof(as_t));
- else
- bgp->confed_peers =
- XMALLOC(MTYPE_BGP_CONFED_LIST,
- (bgp->confed_peers_cnt + 1) * sizeof(as_t));
+ bgp->confed_peers =
+ XREALLOC(MTYPE_BGP_CONFED_LIST, bgp->confed_peers,
+ (bgp->confed_peers_cnt + 1) * sizeof(as_t));
bgp->confed_peers[bgp->confed_peers_cnt] = as;
bgp->confed_peers_cnt++;