From 6b08e2c17167a7d2a06ed0e65db8d5ebf17156a7 Mon Sep 17 00:00:00 2001 From: Albert Chu Date: Tue, 29 Aug 2023 08:09:18 -0700 Subject: [PATCH] Fix various compiler warnings --- libltdl/Makefile.in | 19 ++++++++----------- src/cerebrod/cerebrod_metric_controller.c | 3 +++ src/cerebrod/cerebrod_speaker_data.c | 6 ++++++ src/libs/cerebro/cerebro_event.c | 3 +++ src/libs/cerebro/cerebro_metric_control.c | 3 +++ src/libs/cerebro/cerebro_metric_util.c | 3 +++ src/libs/wrappers/wrappers.c | 4 ++++ src/modules/event/cerebro_event_updown.c | 3 +++ src/modules/metric/cerebro_metric_network.c | 11 +++++------ 9 files changed, 38 insertions(+), 17 deletions(-) diff --git a/libltdl/Makefile.in b/libltdl/Makefile.in index fd5d5658..bda90e5d 100644 --- a/libltdl/Makefile.in +++ b/libltdl/Makefile.in @@ -96,12 +96,11 @@ host_triplet = @host@ @CONVENIENCE_LTDL_TRUE@am__append_3 = libltdlc.la subdir = . ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 -am__aclocal_m4_deps = $(top_srcdir)/../m4/libtool.m4 \ - $(top_srcdir)/../m4/ltargz.m4 $(top_srcdir)/../m4/ltdl.m4 \ - $(top_srcdir)/../m4/ltoptions.m4 \ - $(top_srcdir)/../m4/ltsugar.m4 \ - $(top_srcdir)/../m4/ltversion.m4 \ - $(top_srcdir)/../m4/lt~obsolete.m4 $(top_srcdir)/configure.ac +am__aclocal_m4_deps = $(top_srcdir)/m4/libtool.m4 \ + $(top_srcdir)/m4/ltargz.m4 $(top_srcdir)/m4/ltdl.m4 \ + $(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \ + $(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \ + $(top_srcdir)/configure.ac am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ $(ACLOCAL_M4) DIST_COMMON = $(srcdir)/Makefile.am $(top_srcdir)/configure \ @@ -304,11 +303,9 @@ am__DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/config-h.in \ $(top_srcdir)/../config/install-sh \ $(top_srcdir)/../config/ltmain.sh \ $(top_srcdir)/../config/missing ../config/compile \ - ../config/config.guess ../config/config.sub \ - ../config/depcomp ../config/install-sh \ - ../config/ltmain.sh \ - ../config/missing COPYING.LIB \ - README lt__argz.c lt__dirent.c lt__strl.c + ../config/config.guess ../config/config.sub ../config/depcomp \ + ../config/install-sh ../config/ltmain.sh ../config/missing \ + COPYING.LIB README lt__argz.c lt__dirent.c lt__strl.c DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) distdir = $(PACKAGE)-$(VERSION) top_distdir = $(distdir) diff --git a/src/cerebrod/cerebrod_metric_controller.c b/src/cerebrod/cerebrod_metric_controller.c index fb03610a..64f6dc35 100644 --- a/src/cerebrod/cerebrod_metric_controller.c +++ b/src/cerebrod/cerebrod_metric_controller.c @@ -609,8 +609,11 @@ _send_message_now(int fd, } memset(mm, '\0', sizeof(struct cerebrod_message_metric)); +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wstringop-truncation" /* need not overflow */ strncpy(mm->metric_name, metric_name, CEREBRO_MAX_METRIC_NAME_LEN); +#pragma GCC diagnostic pop mm->metric_value_type = metric_value_type; mm->metric_value_len = metric_value_len; diff --git a/src/cerebrod/cerebrod_speaker_data.c b/src/cerebrod/cerebrod_speaker_data.c index 4416305a..9e448621 100644 --- a/src/cerebrod/cerebrod_speaker_data.c +++ b/src/cerebrod/cerebrod_speaker_data.c @@ -451,8 +451,11 @@ _get_module_metric_value(unsigned int index) goto cleanup; } +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wstringop-truncation" /* need not overflow */ strncpy(mm->metric_name, metric_name, CEREBRO_MAX_METRIC_NAME_LEN); +#pragma GCC diagnostic pop if (metric_module_get_metric_value(metric_handle, index, @@ -538,10 +541,13 @@ _get_userspace_metric_value(struct cerebrod_speaker_metric_info *metric_info) mm = Malloc(sizeof(struct cerebrod_message_metric)); memset(mm, '\0', sizeof(struct cerebrod_message_metric)); +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wstringop-truncation" /* need not overflow */ strncpy(mm->metric_name, metric_info->metric_name, CEREBRO_MAX_METRIC_NAME_LEN); +#pragma GCC diagnostic pop mm->metric_value_type = metric_info->metric_value_type; mm->metric_value_len = metric_info->metric_value_len; diff --git a/src/libs/cerebro/cerebro_event.c b/src/libs/cerebro/cerebro_event.c index 019f3c98..853d993e 100644 --- a/src/libs/cerebro/cerebro_event.c +++ b/src/libs/cerebro/cerebro_event.c @@ -130,7 +130,10 @@ _event_server_request_send(cerebro_t handle, } req.version = CEREBRO_EVENT_SERVER_PROTOCOL_VERSION; +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wstringop-truncation" strncpy(req.event_name, event_name, CEREBRO_MAX_EVENT_NAME_LEN); +#pragma GCC diagnostic pop req.flags = flags; if ((req_len = _event_server_request_marshall(handle, diff --git a/src/libs/cerebro/cerebro_metric_control.c b/src/libs/cerebro/cerebro_metric_control.c index cbb9b328..0db485c8 100644 --- a/src/libs/cerebro/cerebro_metric_control.c +++ b/src/libs/cerebro/cerebro_metric_control.c @@ -270,7 +270,10 @@ _metric_control_request_send(cerebro_t handle, req.version = CEREBRO_METRIC_CONTROL_PROTOCOL_VERSION; req.command = command; req.flags = flags; +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wstringop-truncation" strncpy(req.metric_name, metric_name, CEREBRO_MAX_METRIC_NAME_LEN); +#pragma GCC diagnostic pop req.metric_value_type = metric_value_type; req.metric_value_len = metric_value_len; req.metric_value = metric_value; diff --git a/src/libs/cerebro/cerebro_metric_util.c b/src/libs/cerebro/cerebro_metric_util.c index d51ff8ab..08142acd 100644 --- a/src/libs/cerebro/cerebro_metric_util.c +++ b/src/libs/cerebro/cerebro_metric_util.c @@ -169,7 +169,10 @@ _metric_server_request_send(cerebro_t handle, } req.version = CEREBRO_METRIC_SERVER_PROTOCOL_VERSION; +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wstringop-truncation" strncpy(req.metric_name, metric_name, CEREBRO_MAX_METRIC_NAME_LEN); +#pragma GCC diagnostic pop req.timeout_len = timeout_len; req.flags = flags; diff --git a/src/libs/wrappers/wrappers.c b/src/libs/wrappers/wrappers.c index f11f5cae..1377aedc 100644 --- a/src/libs/wrappers/wrappers.c +++ b/src/libs/wrappers/wrappers.c @@ -65,8 +65,10 @@ void wrap_free(WRAPPERS_ARGS, void *ptr) { void *p = ptr - 2*sizeof(int); +#ifndef NDEBUG int i, size; char *c; +#endif assert(file && function); @@ -76,10 +78,12 @@ wrap_free(WRAPPERS_ARGS, void *ptr) if (!(*((int *)p) == MALLOC_MAGIC)) WRAPPERS_ERR_MSG("free", "memory corruption"); +#ifndef NDEBUG size = *((int *)(p + sizeof(int))); c = (char *)(p + 2*sizeof(int) + size); for (i = 0; i < MALLOC_PAD_LEN; i++) assert(c[i] == (char)MALLOC_PAD_DATA); +#endif free(p); } diff --git a/src/modules/event/cerebro_event_updown.c b/src/modules/event/cerebro_event_updown.c index 10c6988e..9cec7be6 100644 --- a/src/modules/event/cerebro_event_updown.c +++ b/src/modules/event/cerebro_event_updown.c @@ -229,8 +229,11 @@ _create_event(const char *nodename, int state) event->version = CEREBRO_EVENT_PROTOCOL_VERSION; event->err_code = CEREBRO_EVENT_SERVER_PROTOCOL_ERR_SUCCESS; +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wstringop-truncation" strncpy(event->nodename, nodename, CEREBRO_MAX_NODENAME_LEN); strncpy(event->event_name, UPDOWN_EVENT_NAME, CEREBRO_MAX_EVENT_NAME_LEN); +#pragma GCC diagnostic pop event->event_value_type = CEREBRO_DATA_VALUE_TYPE_INT32; event->event_value_len = sizeof(int32_t); if (!(event->event_value = malloc(sizeof(int32_t)))) diff --git a/src/modules/metric/cerebro_metric_network.c b/src/modules/metric/cerebro_metric_network.c index 3f50c42a..83cb179b 100644 --- a/src/modules/metric/cerebro_metric_network.c +++ b/src/modules/metric/cerebro_metric_network.c @@ -148,7 +148,6 @@ cerebro_metric_get_network(u_int64_t *bytesin, u_int64_t tx_bytes; u_int32_t rx_packets, rx_errs; u_int32_t tx_packets, tx_errs; - u_int32_t temp; char *strptr; /* skip the device name */ @@ -177,31 +176,31 @@ cerebro_metric_get_network(u_int64_t *bytesin, CEREBRO_ERR(("%s parse error", NETWORK_FILE)); goto cleanup; } - temp = strtoul(strptr, &strptr, 10); /* drop */ + (void)strtoul(strptr, &strptr, 10); /* drop */ if (!strptr) { CEREBRO_ERR(("%s parse error", NETWORK_FILE)); goto cleanup; } - temp = strtoul(strptr, &strptr, 10); /* fifo */ + (void)strtoul(strptr, &strptr, 10); /* fifo */ if (!strptr) { CEREBRO_ERR(("%s parse error", NETWORK_FILE)); goto cleanup; } - temp = strtoul(strptr, &strptr, 10); /* frame */ + (void)strtoul(strptr, &strptr, 10); /* frame */ if (!strptr) { CEREBRO_ERR(("%s parse error", NETWORK_FILE)); goto cleanup; } - temp = strtoul(strptr, &strptr, 10); /* compressed */ + (void)strtoul(strptr, &strptr, 10); /* compressed */ if (!strptr) { CEREBRO_ERR(("%s parse error", NETWORK_FILE)); goto cleanup; } - temp = strtoul(strptr, &strptr, 10); /* multicast */ + (void)strtoul(strptr, &strptr, 10); /* multicast */ if (!strptr) { CEREBRO_ERR(("%s parse error", NETWORK_FILE));