Merge pull request #2218 from RincewindsHat/fix/compiler_warnings

Fix some minor compiler warnings
This commit is contained in:
Lorenz Kästle 2026-01-09 14:18:31 +01:00 committed by GitHub
commit f694f4cd4d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 61 additions and 40 deletions

View file

@ -810,7 +810,7 @@ elif ps axwo 'stat comm vsz rss user uid pid ppid etime args' 2>/dev/null | \
then
ac_cv_ps_varlist="[procstat,&procuid,&procpid,&procppid,&procvsz,&procrss,&procpcpu,procetime,procprog,&pos]"
ac_cv_ps_command="$PATH_TO_PS axwo 'stat uid pid ppid vsz rss pcpu etime comm args'"
ac_cv_ps_format="%s %u %d %d %d %d %f %s %s %n"
ac_cv_ps_format="%s %d %d %d %d %d %f %s %s %n"
ac_cv_ps_cols=10
AC_MSG_RESULT([$ac_cv_ps_command])

View file

@ -352,15 +352,17 @@ static int add_option(FILE *filePointer, np_arg_list **optlst) {
optnew->next = NULL;
read_pos = 0;
optnew->arg = malloc(cfg_len + 1);
size_t arg_length = cfg_len + 1;
optnew->arg = malloc(arg_length);
/* 1-character params needs only one dash */
if (opt_len == 1) {
strncpy(&optnew->arg[read_pos], "-", 1);
strncpy(&optnew->arg[read_pos], "-", arg_length);
read_pos += 1;
} else {
strncpy(&optnew->arg[read_pos], "--", 2);
strncpy(&optnew->arg[read_pos], "--", arg_length);
read_pos += 2;
}
strncpy(&optnew->arg[read_pos], optptr, opt_len);
read_pos += opt_len;
if (value) {

View file

@ -55,7 +55,7 @@ const char *email = "devel@monitoring-plugins.org";
#include <sys/time.h>
#if defined(SIOCGIFADDR)
#include <sys/ioctl.h>
# include <sys/ioctl.h>
#endif /* SIOCGIFADDR */
#include <errno.h>
#include <signal.h>
@ -1782,6 +1782,7 @@ static void set_source_ip(char *arg, const int icmp_sock, sa_family_t addr_famil
/* TODO: Move this to netutils.c and also change check_dhcp to use that. */
static in_addr_t get_ip_address(const char *ifname, const int icmp_sock) {
// TODO: Rewrite this so the function return an error and we exit somewhere else
struct sockaddr_in ip_address;
ip_address.sin_addr.s_addr = 0; // Fake initialization to make compiler happy
#if defined(SIOCGIFADDR)
@ -1797,6 +1798,9 @@ static in_addr_t get_ip_address(const char *ifname, const int icmp_sock) {
memcpy(&ip_address, &ifr.ifr_addr, sizeof(ip_address));
#else
// fake operation to make the compiler happy
(void)icmp_sock;
(void)ifname;
errno = 0;
crash("Cannot get interface IP address on this platform.");
@ -2046,7 +2050,7 @@ unsigned short icmp_checksum(uint16_t *packet, size_t packet_size) {
/* mop up the occasional odd byte */
if (packet_size == 1) {
sum += *((uint8_t *)packet - 1);
sum += *((uint8_t *)packet);
}
sum = (sum >> 16) + (sum & 0xffff); /* add hi 16 to low 16 */
@ -2245,7 +2249,7 @@ mp_subcheck evaluate_target(ping_target target, check_icmp_mode_switches modes,
* round trip jitter, but double the impact to latency
* then add 10 for protocol latencies (in milliseconds).
*/
EffectiveLatency = ((double)rta / 1000) + target.jitter * 2 + 10;
EffectiveLatency = ((double)rta / 1000) + (target.jitter * 2) + 10;
double R;
if (EffectiveLatency < 160) {
@ -2404,25 +2408,32 @@ mp_subcheck evaluate_target(ping_target target, check_icmp_mode_switches modes,
if (modes.score_mode) {
mp_subcheck sc_score = mp_subcheck_init();
sc_score = mp_set_subcheck_default_state(sc_score, STATE_OK);
xasprintf(&sc_score.output, "Score %f", score);
if (score <= crit.score) {
sc_score = mp_set_subcheck_state(sc_score, STATE_CRITICAL);
xasprintf(&sc_score.output, "%s <= %f", sc_score.output, crit.score);
} else if (score <= warn.score) {
sc_score = mp_set_subcheck_state(sc_score, STATE_WARNING);
xasprintf(&sc_score.output, "%s <= %f", sc_score.output, warn.score);
}
if (target.icmp_recv > 1) {
xasprintf(&sc_score.output, "Score %f", score);
if (packet_loss < 100) {
mp_perfdata pd_score = perfdata_init();
xasprintf(&pd_score.label, "%sscore", address);
pd_score.value = mp_create_pd_value(score);
pd_score.warn = mp_range_set_end(pd_score.warn, mp_create_pd_value(warn.score));
pd_score.crit = mp_range_set_end(pd_score.crit, mp_create_pd_value(crit.score));
pd_score.min = mp_create_pd_value(0);
pd_score.max = mp_create_pd_value(100);
mp_add_perfdata_to_subcheck(&sc_score, pd_score);
if (score <= crit.score) {
sc_score = mp_set_subcheck_state(sc_score, STATE_CRITICAL);
xasprintf(&sc_score.output, "%s <= %f", sc_score.output, crit.score);
} else if (score <= warn.score) {
sc_score = mp_set_subcheck_state(sc_score, STATE_WARNING);
xasprintf(&sc_score.output, "%s <= %f", sc_score.output, warn.score);
}
if (packet_loss < 100) {
mp_perfdata pd_score = perfdata_init();
xasprintf(&pd_score.label, "%sscore", address);
pd_score.value = mp_create_pd_value(score);
pd_score.warn = mp_range_set_end(pd_score.warn, mp_create_pd_value(warn.score));
pd_score.crit = mp_range_set_end(pd_score.crit, mp_create_pd_value(crit.score));
pd_score.min = mp_create_pd_value(0);
pd_score.max = mp_create_pd_value(100);
mp_add_perfdata_to_subcheck(&sc_score, pd_score);
}
} else {
// score mode disabled due to not enough received packages
xasprintf(&sc_score.output, "Score mode disabled, not enough packets received");
}
mp_add_subcheck_to_subcheck(&result, sc_score);

View file

@ -775,19 +775,23 @@ redir_wrapper redir(curlhelp_write_curlbuf *header_buf, const check_curl_config
/* missing components have null,null in their UriTextRangeA
* add query parameters if they exist.
*/
if (uri.query.first && uri.query.afterLast){
// Ensure we have space for '?' + query_str + '\0' ahead of time, instead of calling strncat twice
if (uri.query.first && uri.query.afterLast) {
// Ensure we have space for '?' + query_str + '\0' ahead of time, instead of calling strncat
// twice
size_t current_len = strlen(new_url);
size_t remaining_space = DEFAULT_BUFFER_SIZE - current_len - 1;
const char* query_str = uri_string(uri.query, buf, DEFAULT_BUFFER_SIZE);
const char *query_str = uri_string(uri.query, buf, DEFAULT_BUFFER_SIZE);
size_t query_str_len = strlen(query_str);
if (remaining_space >= query_str_len + 1) {
strcat(new_url, "?");
strcat(new_url, query_str);
}else{
die(STATE_UNKNOWN, _("HTTP UNKNOWN - No space to add query part of size %d to the buffer, buffer has remaining size %d"), query_str_len , current_len );
} else {
die(STATE_UNKNOWN,
_("HTTP UNKNOWN - No space to add query part of size %zu to the buffer, buffer has "
"remaining size %zu"),
query_str_len, current_len);
}
}
@ -1501,8 +1505,8 @@ void print_help(void) {
printf(" %s\n", "-I, --IP-address=ADDRESS");
printf(" %s\n",
"IP address or name (use numeric address if possible to bypass DNS lookup).");
printf(" %s\n",
"This overwrites the network address of the target while leaving everything else (HTTP headers) as they are");
printf(" %s\n", "This overwrites the network address of the target while leaving everything "
"else (HTTP headers) as they are");
printf(" %s\n", "-p, --port=INTEGER");
printf(" %s", _("Port number (default: "));
printf("%d)\n", HTTP_PORT);
@ -1566,7 +1570,8 @@ void print_help(void) {
printf(" %s\n", _("String to expect in the content"));
printf(" %s\n", "-u, --url=PATH");
printf(" %s\n", _("URL to GET or POST (default: /)"));
printf(" %s\n", _("This is the part after the address in a URL, so for \"https://example.com/index.html\" it would be '-u /index.html'"));
printf(" %s\n", _("This is the part after the address in a URL, so for "
"\"https://example.com/index.html\" it would be '-u /index.html'"));
printf(" %s\n", "-P, --post=STRING");
printf(" %s\n", _("URL decoded http POST data"));
printf(" %s\n",
@ -1712,7 +1717,8 @@ void print_help(void) {
printf(" %s\n", _("It is recommended to use an environment proxy like:"));
printf(" %s\n",
_("https_proxy=http://192.168.100.35:3128 ./check_curl -H www.verisign.com -S"));
printf(" %s\n", _("legacy proxy requests in check_http style might still work, but are frowned upon, so DONT:"));
printf(" %s\n", _("legacy proxy requests in check_http style might still work, but are frowned "
"upon, so DONT:"));
printf(" %s\n", _("check_curl -I 192.168.100.35 -p 3128 -u https://www.verisign.com/ -S -j "
"CONNECT -H www.verisign.com "));
printf(" %s\n", _("all these options are needed: -I <proxy> -p <proxy-port> -u <check-url> "

View file

@ -1214,7 +1214,7 @@ mp_subcheck check_curl_certificate_checks(CURL *curl, X509 *cert, int warn_days_
cert_ptr_union cert_ptr = {0};
cert_ptr.to_info = NULL;
CURLcode res = curl_easy_getinfo(curl, CURLINFO_CERTINFO, &cert_ptr.to_info);
CURLcode res = curl_easy_getinfo(curl, CURLINFO_CERTINFO, &cert_ptr.to_certinfo);
if (!res && cert_ptr.to_info) {
# ifdef USE_OPENSSL
/* We have no OpenSSL in libcurl, but we can use OpenSSL for X509 cert

View file

@ -36,7 +36,8 @@ int check_snmp_set_thresholds(const char *threshold_string, check_snmp_test_unit
threshold_string++;
}
for (char *ptr = strtok(threshold_string, ", "); ptr != NULL;
char *thr_string_copy = strdup(threshold_string);
for (char *ptr = strtok(thr_string_copy, ", "); ptr != NULL;
ptr = strtok(NULL, ", "), tu_index++) {
if (tu_index > max_test_units) {
@ -64,6 +65,7 @@ int check_snmp_set_thresholds(const char *threshold_string, check_snmp_test_unit
}
}
free(thr_string_copy);
} else {
// Single value
// only valid for the first test unit
@ -843,8 +845,8 @@ char *_np_state_calculate_location_prefix(void) {
* Sets variables. Generates filename. Returns np_state_key. die with
* UNKNOWN if exception
*/
state_key np_enable_state(char *keyname, int expected_data_version, char *plugin_name, int argc,
char **argv) {
state_key np_enable_state(char *keyname, int expected_data_version, const char *plugin_name,
int argc, char **argv) {
state_key *this_state = (state_key *)calloc(1, sizeof(state_key));
if (this_state == NULL) {
die(STATE_UNKNOWN, _("Cannot allocate memory: %s"), strerror(errno));
@ -869,7 +871,7 @@ state_key np_enable_state(char *keyname, int expected_data_version, char *plugin
tmp_char++;
}
this_state->name = temp_keyname;
this_state->plugin_name = plugin_name;
this_state->plugin_name = (char *)plugin_name;
this_state->data_version = expected_data_version;
this_state->state_data = NULL;

View file

@ -66,6 +66,6 @@ typedef struct state_key_struct {
} state_key;
state_data *np_state_read(state_key stateKey);
state_key np_enable_state(char *keyname, int expected_data_version, char *plugin_name, int argc,
char **argv);
state_key np_enable_state(char *keyname, int expected_data_version, const char *plugin_name,
int argc, char **argv);
void np_state_write_string(state_key stateKey, time_t timestamp, char *stringToStore);