aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichele Papalini <micpapal@cisco.com>2023-02-02 17:49:46 +0100
committerMichele Papalini <micpapal@cisco.com>2023-02-07 10:25:01 +0100
commit8a7e75e84a31180d51b9970d526709ec4dca2030 (patch)
tree48c1d88f0a5635e75fa9fc0eb898b861b42477e8
parentb96d1545a8d2a173dc5911ed0bca3e04dbb02176 (diff)
fix(hicn): fix bugs reported by sonarqube
Ref: HICN-837 Signed-off-by: Michele Papalini <micpapal@cisco.com> Change-Id: I0d02a11361b1ba5ad50123b2dd142c961998922f
-rw-r--r--apps/higet/higet.cc1
-rw-r--r--ctrl/facemgr/src/facelet.c4
-rw-r--r--ctrl/libhicnctrl/src/modules/hicn_plugin/route.c10
-rw-r--r--ctrl/libhicnctrl/src/objects/connection.c1
-rw-r--r--hicn-light/src/hicn/core/mapme.c9
-rw-r--r--hicn-plugin/libvapi-safe/src/vapi_safe.cc11
-rw-r--r--hicn-plugin/src/pcs.h2
-rw-r--r--hicn-plugin/src/test/vpp.c3
-rw-r--r--lib/src/policy.c3
-rw-r--r--libtransport/includes/hicn/transport/core/connector.h2
-rw-r--r--libtransport/src/core/memif_connector.cc8
-rw-r--r--libtransport/src/core/pending_interest.h8
-rw-r--r--libtransport/src/protocols/incremental_indexer_bytestream.h2
-rw-r--r--libtransport/src/protocols/rtc/rtc_indexer.h2
-rw-r--r--libtransport/src/utils/fd_deadline_timer.h3
15 files changed, 38 insertions, 31 deletions
diff --git a/apps/higet/higet.cc b/apps/higet/higet.cc
index dcd55e755..77cbb52d2 100644
--- a/apps/higet/higet.cc
+++ b/apps/higet/higet.cc
@@ -280,7 +280,6 @@ int http_main(int argc, char **argv) {
default:
usage(argv[0]);
exit(EXIT_FAILURE);
- break;
}
}
diff --git a/ctrl/facemgr/src/facelet.c b/ctrl/facemgr/src/facelet.c
index a299cc5ac..4723b8940 100644
--- a/ctrl/facemgr/src/facelet.c
+++ b/ctrl/facemgr/src/facelet.c
@@ -1047,8 +1047,6 @@ int facelet_snprintf(char *s, size_t size, const facelet_t *facelet) {
rc = snprintf(cur, s + size - cur, "}>");
if (rc < 0) return rc;
cur += rc;
- if (cur >= s + size) return (int)(cur - s);
-
return (int)(cur - s);
}
@@ -1222,7 +1220,5 @@ int facelet_snprintf_json(char *s, size_t size, const facelet_t *facelet,
rc = snprintf(cur, s + size - cur, "%*s%s", 4 * indent, "", "}");
if (rc < 0) return rc;
cur += rc;
- if (cur >= s + size) return (int)(cur - s);
-
return (int)(cur - s);
}
diff --git a/ctrl/libhicnctrl/src/modules/hicn_plugin/route.c b/ctrl/libhicnctrl/src/modules/hicn_plugin/route.c
index e066862e2..4c9f8a638 100644
--- a/ctrl/libhicnctrl/src/modules/hicn_plugin/route.c
+++ b/ctrl/libhicnctrl/src/modules/hicn_plugin/route.c
@@ -39,8 +39,6 @@ static vapi_error_e parse_route_create(
vapi_payload_ip_route_add_del_reply *reply) {
if (reply == NULL || rv != VAPI_OK) return rv;
- if (reply->retval != VAPI_OK) return reply->retval;
-
return reply->retval;
}
@@ -114,6 +112,10 @@ static int _vpp_route_create(hc_sock_t *sock, hc_route_t *route) {
if (hicn_ip_address_is_v4(&(face->remote_addr)) &&
hicn_ip_address_is_v4(&(face->local_addr))) {
msg2 = vapi_alloc_hicn_api_udp_tunnel_add_del(s->g_vapi_ctx_instance);
+ if (msg2 == NULL) {
+ ret = -1;
+ goto done;
+ }
memcpy(msg2->payload.src_addr.un.ip4, &face->local_addr.v4,
sizeof(ip4_address_t));
msg2->payload.src_addr.af = ADDRESS_IP4;
@@ -125,6 +127,10 @@ static int _vpp_route_create(hc_sock_t *sock, hc_route_t *route) {
} else if (!hicn_ip_address_is_v4(&(route->face.remote_addr)) &&
!hicn_ip_address_is_v4(&(route->face.local_addr))) {
msg2 = vapi_alloc_hicn_api_udp_tunnel_add_del(s->g_vapi_ctx_instance);
+ if (msg2 == NULL) {
+ ret = -1;
+ goto done;
+ }
memcpy(msg2->payload.src_addr.un.ip6, &face->local_addr.v6,
sizeof(ip6_address_t));
msg2->payload.src_addr.af = ADDRESS_IP6;
diff --git a/ctrl/libhicnctrl/src/objects/connection.c b/ctrl/libhicnctrl/src/objects/connection.c
index 0f8bafb10..ca09d9a54 100644
--- a/ctrl/libhicnctrl/src/objects/connection.c
+++ b/ctrl/libhicnctrl/src/objects/connection.c
@@ -189,7 +189,6 @@ int hc_connection_cmp(const hc_connection_t *c1, const hc_connection_t *c2) {
if (rc != 0) return rc;
rc = INT_CMP(c1->remote_port, c2->remote_port);
- if (rc != 0) return rc;
return rc;
}
diff --git a/hicn-light/src/hicn/core/mapme.c b/hicn-light/src/hicn/core/mapme.c
index fede52cae..53c7ec9da 100644
--- a/hicn-light/src/hicn/core/mapme.c
+++ b/hicn-light/src/hicn/core/mapme.c
@@ -302,17 +302,10 @@ static void mapme_create_tfib(const mapme_t *mapme, fib_entry_t *entry) {
*/
static hicn_mapme_type_t mapme_get_type_from_heuristic(const mapme_t *mapme,
fib_entry_t *entry) {
+#if 0
if (fib_entry_has_local_nexthop(entry))
/* We are a producer for this entry, send update */
return UPDATE;
-
-#if 0 /* interplay of IU/IN */
- if (TFIB(fib_entry)->lastAckedUpdate == 0) {
- return UPDATE;
- } else {
- Ticks interval = now - TFIB(fib_entry)->lastAckedUpdate;
- return (T2NS(interval) > MS2NS(mapme->timescale)) ? UPDATE : NOTIFICATION;
- }
#else /* Always send IU */
return UPDATE;
#endif
diff --git a/hicn-plugin/libvapi-safe/src/vapi_safe.cc b/hicn-plugin/libvapi-safe/src/vapi_safe.cc
index 8747ca738..dc2db329e 100644
--- a/hicn-plugin/libvapi-safe/src/vapi_safe.cc
+++ b/hicn-plugin/libvapi-safe/src/vapi_safe.cc
@@ -312,16 +312,21 @@ public:
~VapiGlobalConnection ()
{
- std::cout << "\"adios1" << std::endl;
if (!isConnected ())
{
return;
}
- std::cout << "\"adios" << std::endl;
std::unique_lock<std::mutex> lock (vapi_mtx_);
vapi_disconnect (vapi_ctx_);
vapi_ctx_free (vapi_ctx_);
- timer_.cancel ();
+ try
+ {
+ timer_.cancel ();
+ }
+ catch (asio::system_error e)
+ {
+ // quit anyway
+ }
}
private:
diff --git a/hicn-plugin/src/pcs.h b/hicn-plugin/src/pcs.h
index 86fb72cc9..2019ddb73 100644
--- a/hicn-plugin/src/pcs.h
+++ b/hicn-plugin/src/pcs.h
@@ -647,7 +647,7 @@ hicn_pcs_lookup_one (hicn_pit_cs_t *pitcs, const hicn_name_t *name,
*pcs_entry = hicn_pcs_entry_get_entry_from_index (pitcs, (u32) (kv.value));
// If the search is successful, we MUST find the entry in the pool.
- ALWAYS_ASSERT (*pcs_entry);
+ ALWAYS_ASSERT (pcs_entry);
// If entry found and it is a CS entry, let's update the LRU
if (hicn_pcs_entry_is_cs (*pcs_entry))
diff --git a/hicn-plugin/src/test/vpp.c b/hicn-plugin/src/test/vpp.c
index 761e55759..e1f38e23d 100644
--- a/hicn-plugin/src/test/vpp.c
+++ b/hicn-plugin/src/test/vpp.c
@@ -199,6 +199,7 @@ vpp_init_internal (int argc, char *argv[])
if (arg == NULL)
{
free (argv_);
+ fclose (fp);
return 1;
}
argv_[argc_ - 1] = arg;
@@ -244,7 +245,7 @@ vpp_init_internal (int argc, char *argv[])
{
sizep = (u8 *) argv[i + 1];
size = 0;
- while (*sizep >= '0' && *sizep <= '9')
+ while (sizep && *sizep >= '0' && *sizep <= '9')
{
size *= 10;
size += *sizep++ - '0';
diff --git a/lib/src/policy.c b/lib/src/policy.c
index 0b4850b93..4a4b9fa89 100644
--- a/lib/src/policy.c
+++ b/lib/src/policy.c
@@ -69,8 +69,5 @@ policy_tag_state_snprintf (char *s, size_t size,
if (rc < 0)
return rc;
cur += rc;
- if (size != 0 && cur >= s + size)
- return (int) (cur - s);
-
return (int) (cur - s);
}
diff --git a/libtransport/includes/hicn/transport/core/connector.h b/libtransport/includes/hicn/transport/core/connector.h
index be191fb4a..7882b285d 100644
--- a/libtransport/includes/hicn/transport/core/connector.h
+++ b/libtransport/includes/hicn/transport/core/connector.h
@@ -96,7 +96,7 @@ class Connector : public std::enable_shared_from_this<Connector> {
}
template <typename OnReconnect>
- void setReconnectCallback(const OnReconnect &&callback) {
+ void setReconnectCallback(OnReconnect &&callback) {
on_reconnect_callback_ = std::forward<OnReconnect>(callback);
}
diff --git a/libtransport/src/core/memif_connector.cc b/libtransport/src/core/memif_connector.cc
index fb38a6e23..a224beb11 100644
--- a/libtransport/src/core/memif_connector.cc
+++ b/libtransport/src/core/memif_connector.cc
@@ -55,7 +55,13 @@ MemifConnector::MemifConnector(PacketReceivedCallback &&receive_callback,
log2_ring_size_(klog2_ring_size),
max_memif_bufs_(1 << klog2_ring_size) {}
-MemifConnector::~MemifConnector() { close(); }
+MemifConnector::~MemifConnector() {
+ try {
+ close();
+ } catch (errors::RuntimeException &e) {
+ // do nothing
+ }
+}
void MemifConnector::connect(uint32_t memif_id, long memif_mode,
const std::string &socket_filename,
diff --git a/libtransport/src/core/pending_interest.h b/libtransport/src/core/pending_interest.h
index b901e7d97..f49348bac 100644
--- a/libtransport/src/core/pending_interest.h
+++ b/libtransport/src/core/pending_interest.h
@@ -62,7 +62,13 @@ class PendingInterest {
timer_.async_wait(std::forward<Handler>(cb));
}
- void cancelTimer() { timer_.cancel(); }
+ void cancelTimer() {
+ try {
+ timer_.cancel();
+ } catch (asio::system_error &e) {
+ // do nothing
+ }
+ }
Interest::Ptr &&getInterest() { return std::move(interest_); }
diff --git a/libtransport/src/protocols/incremental_indexer_bytestream.h b/libtransport/src/protocols/incremental_indexer_bytestream.h
index 422e49ecd..4f9b6126f 100644
--- a/libtransport/src/protocols/incremental_indexer_bytestream.h
+++ b/libtransport/src/protocols/incremental_indexer_bytestream.h
@@ -48,7 +48,7 @@ class IncrementalIndexer : public Indexer {
IncrementalIndexer(const IncrementalIndexer &other) = delete;
IncrementalIndexer(IncrementalIndexer &&other)
- : Indexer(std::forward<Indexer>(other)),
+ : Indexer(other),
final_suffix_(other.final_suffix_),
first_suffix_(other.first_suffix_),
next_download_suffix_(other.next_download_suffix_),
diff --git a/libtransport/src/protocols/rtc/rtc_indexer.h b/libtransport/src/protocols/rtc/rtc_indexer.h
index cda156b22..f87fcaaa2 100644
--- a/libtransport/src/protocols/rtc/rtc_indexer.h
+++ b/libtransport/src/protocols/rtc/rtc_indexer.h
@@ -47,7 +47,7 @@ class RtcIndexer : public Indexer {
n_fec_(0),
n_current_fec_(n_fec_) {}
- RtcIndexer(RtcIndexer &&other) : Indexer(std::forward<Indexer>(other)) {}
+ RtcIndexer(RtcIndexer &&other) : Indexer(other) {}
~RtcIndexer() {}
diff --git a/libtransport/src/utils/fd_deadline_timer.h b/libtransport/src/utils/fd_deadline_timer.h
index cf0cde112..7ecbba69b 100644
--- a/libtransport/src/utils/fd_deadline_timer.h
+++ b/libtransport/src/utils/fd_deadline_timer.h
@@ -92,8 +92,7 @@ class FdDeadlineTimer : public DeadlineTimer<FdDeadlineTimer> {
template <typename T, typename R>
void expiresFromNowImpl(std::chrono::duration<T, R> &&duration) {
std::memset(&new_value_, 0, sizeof(new_value_));
- new_value_.it_value = std::chrono::duration_cast<struct timespec>(
- std::forward<std::chrono::duration<T, R>>(duration));
+ new_value_.it_value = std::chrono::duration_cast<struct timespec>(duration);
}
template <typename TimePoint,