Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
fb6f72a
common/common.c: common/common.c: snprintfcat(): sort out the messy r…
jimklimov Nov 20, 2020
05699fb
common/common.c: common/common.c: snprintfcat(): replace asserts by n…
jimklimov Nov 20, 2020
d5ca538
common/str.c: str_to_{u,}short{,_strict}() routines: explicit cast fr…
jimklimov Nov 20, 2020
e704c18
common/upsconf.c: conf_args(): fix numargs type
jimklimov Nov 20, 2020
531e2dc
drivers/liebert-esp2.c: fix indentation
jimklimov Nov 25, 2020
8e58a2a
common/strerror.c: do not warn about unreachable code in the web of i…
jimklimov Nov 25, 2020
f84a847
drivers/bcmxcp.c: do not "break" just after "return"
jimklimov Nov 25, 2020
e6b602a
drivers/bestfcom.c: do not "break" just after "fatalx()"
jimklimov Nov 25, 2020
fdd20b4
drivers/nutdrv_qx.c: wrap unreachable exit() added due to earlier com…
jimklimov Nov 25, 2020
902ac73
drivers/nutdrv_atcl_usb.c: copy-paste typo fix about unreachable code
jimklimov Nov 26, 2020
04d7820
drivers/libusb.c: copy-paste typo fix about unreachable code
jimklimov Nov 26, 2020
3560afb
drivers/libshut.c: satisfy pedantic macro parser (defined vs. used va…
jimklimov Nov 25, 2020
fef6988
drivers/hidparser.c: satisfy pedantic macro parser (defined vs. used …
jimklimov Nov 25, 2020
ae5854e
drivers/al175.c: align method docs with param names
jimklimov Nov 25, 2020
f470a1a
drivers/netxml-ups.c: align method docs with supported keywords
jimklimov Nov 25, 2020
a350f73
drivers/netxml-ups.c: align method docs with param names
jimklimov Nov 25, 2020
355920f
tools/nut-scanner/scan_snmp.c: mark up NUT_UNUSED_VARIABLEs
jimklimov Nov 25, 2020
0e252db
tools/nut-scanner/scan_xml_http.c: mark up NUT_UNUSED_VARIABLEs
jimklimov Nov 25, 2020
37aef38
tools/nut-scanner/scan_ipmi.c: mark up NUT_UNUSED_VARIABLEs
jimklimov Nov 25, 2020
d5f7261
tools/nut-scanner/scan_avahi.c: mark up NUT_UNUSED_VARIABLEs
jimklimov Nov 25, 2020
2a75a17
clients/upsimage.c: annotate lots of routines with noreturn attr
jimklimov Nov 25, 2020
d129231
clients/upsimage.c: wrap unreachable exit() added due to earlier comp…
jimklimov Nov 25, 2020
a875f84
clients/upsmon.c: annotate forceshutdown() with noreturn attr
jimklimov Nov 25, 2020
bb58bfd
drivers/al175.c: annotate upsdrv_shutdown() with noreturn attr
jimklimov Nov 25, 2020
a6195ab
drivers/powercom.c: annotate shutdown*() with noreturn attr
jimklimov Nov 25, 2020
c5add0c
drivers/riello_usb.c: annotate shutdown*() with noreturn attr
jimklimov Nov 25, 2020
595a79f
drivers/powercom.c: annotate upsdrv_shutdown() with noreturn attr
jimklimov Nov 25, 2020
bbdea16
drivers/powerman-pdu.c: annotate upsdrv_shutdown() with noreturn attr
jimklimov Nov 25, 2020
9043ede
drivers/powercom.c: wrap unreachable exit() added due to earlier comp…
jimklimov Nov 25, 2020
3d7ce46
drivers/netxml-ups.c: netxml_alarm_subscribe(): explicitly cast range…
jimklimov Nov 25, 2020
839a7e4
drivers/al175.c: declare function(void) prototypes explicitly
jimklimov Nov 25, 2020
9140376
tools/nut-scanner/scan_snmp.c: do not wrap variable definitions into …
jimklimov Nov 25, 2020
ce5ff63
Merge branch 'master' into fightwarn-unreachable-code
jimklimov Nov 27, 2020
2b5dde7
Merge branch 'master' into fightwarn-unreachable-code
jimklimov Nov 28, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 63 additions & 4 deletions clients/upsimage.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,17 @@ static void drawscale(
}

/* draws the bar style indicator */
static void drawbar(
int lvllo, int lvlhi, /* min and max numbers on the scale */
int step, int step5, int step10, /* steps for minor, submajor and major dashes */
int redlo1, int redhi1, /* first red zone start and end */
int redlo2, int redhi2, /* second red zone start and end */
int grnlo, int grnhi, /* green zone start and end */
double value, /* UPS variable value to draw */
const char *format /* printf style format to be used when rendering summary text */
)
__attribute__((noreturn));

static void drawbar(
int lvllo, int lvlhi, /* min and max numbers on the scale */
int step, int step5, int step10, /* steps for minor, submajor and major dashes */
Expand Down Expand Up @@ -284,6 +295,9 @@ static void drawbar(
}

/* draws the error image */
static void noimage(const char *fmt, ...)
__attribute__((noreturn));

static void noimage(const char *fmt, ...)
{
gdImagePtr im;
Expand Down Expand Up @@ -331,13 +345,23 @@ static void noimage(const char *fmt, ...)

drawimage(im);

/* NOTE: Earlier code called noimage() and then exit(EXIT_FAILURE);
* to signal an error via process exit code. Now that drawimage()
* always ends with exit(EXIT_SUCCESS) - which might make webserver
* feel good - the command-line use if any suffers no error returns.
*/

/* NOTREACHED */
}

/* draws bar indicator when minimum, nominal or maximum values for the given
UPS variable can be determined.
deviation < 0 means that values below nom should be grey instead of
green */
static void drawgeneralbar(double var, int min, int nom, int max,
int deviation, const char *format)
__attribute__((noreturn));

static void drawgeneralbar(double var, int min, int nom, int max,
int deviation, const char *format)
{
Expand Down Expand Up @@ -397,6 +421,10 @@ static void drawgeneralbar(double var, int min, int nom, int max,
}

/* draws input and output voltage bar style indicators */
static void draw_utility(double var, int min, int nom, int max,
int deviation, const char *format)
__attribute__((noreturn));

static void draw_utility(double var, int min, int nom, int max,
int deviation, const char *format)
{
Expand Down Expand Up @@ -440,6 +468,10 @@ static void draw_utility(double var, int min, int nom, int max,
}

/* draws battery.percent bar style indicator */
static void draw_battpct(double var, int min, int nom,
int max, int deviation, const char *format)
__attribute__((noreturn));

static void draw_battpct(double var, int min, int nom,
int max, int deviation, const char *format)
{
Expand All @@ -455,6 +487,10 @@ static void draw_battpct(double var, int min, int nom,
}

/* draws battery.voltage bar style indicator */
static void draw_battvolt(double var, int min, int nom, int max,
int deviation, const char *format)
__attribute__((noreturn));

static void draw_battvolt(double var, int min, int nom, int max,
int deviation, const char *format)
{
Expand Down Expand Up @@ -501,6 +537,11 @@ static void draw_battvolt(double var, int min, int nom, int max,
}

/* draws ups.load bar style indicator */
static void draw_upsload(double var, int min,
int nom, int max,
int deviation, const char *format)
__attribute__((noreturn));

static void draw_upsload(double var, int min,
int nom, int max,
int deviation, const char *format)
Expand All @@ -514,6 +555,10 @@ static void draw_upsload(double var, int min,
}

/* draws temperature bar style indicator */
static void draw_temperature(double var, int min, int nom, int max,
int deviation, const char *format)
__attribute__((noreturn));

static void draw_temperature(double var, int min, int nom, int max,
int deviation, const char *format)
{
Expand All @@ -526,6 +571,10 @@ static void draw_temperature(double var, int min, int nom, int max,
}

/* draws humidity bar style indicator */
static void draw_humidity(double var, int min, int nom, int max,
int deviation, const char *format)
__attribute__((noreturn));

static void draw_humidity(double var, int min, int nom, int max,
int deviation, const char *format)
{
Expand Down Expand Up @@ -581,13 +630,17 @@ int main(int argc, char **argv)

if (upscli_splitname(monhost, &upsname, &hostname, &port) != 0) {
noimage("Invalid UPS definition (upsname[@hostname[:port]])\n");
exit(EXIT_FAILURE);
#ifndef HAVE___ATTRIBUTE__NORETURN
exit(EXIT_FAILURE); /* Should not get here in practice, but compiler is afraid we can fall through */
#endif
}

if (upscli_connect(&ups, hostname, port, 0) < 0) {
noimage("Can't connect to server:\n%s\n",
upscli_strerror(&ups));
exit(EXIT_FAILURE);
#ifndef HAVE___ATTRIBUTE__NORETURN
exit(EXIT_FAILURE); /* Should not get here in practice, but compiler is afraid we can fall through */
#endif
}

for (i = 0; imgvar[i].name; i++)
Expand All @@ -597,7 +650,9 @@ int main(int argc, char **argv)
registered with this variable */
if (!imgvar[i].drawfunc) {
noimage("Draw function N/A");
exit(EXIT_FAILURE);
#ifndef HAVE___ATTRIBUTE__NORETURN
exit(EXIT_FAILURE); /* Should not get here in practice, but compiler is afraid we can fall through */
#endif
}

/* get the variable value */
Expand All @@ -608,7 +663,9 @@ int main(int argc, char **argv)
snprintf(str, sizeof(str), "%s N/A",
imgvar[i].name);
noimage(str);
exit(EXIT_FAILURE);
#ifndef HAVE___ATTRIBUTE__NORETURN
exit(EXIT_FAILURE); /* Should not get here in practice, but compiler is afraid we can fall through */
#endif
}

/* when getting minimum, nominal and maximum values,
Expand Down Expand Up @@ -661,7 +718,9 @@ int main(int argc, char **argv)
}

noimage("Unknown display");
#ifndef HAVE___ATTRIBUTE__NORETURN
exit(EXIT_FAILURE);
#endif
}

imgvar_t imgvar[] = {
Expand Down
3 changes: 3 additions & 0 deletions clients/upsmon.c
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,9 @@ static void slavesync(void)
}
}

static void forceshutdown(void)
__attribute__((noreturn));

static void forceshutdown(void)
{
utype_t *ups;
Expand Down
16 changes: 13 additions & 3 deletions common/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#include <ctype.h>
#include <syslog.h>
#include <errno.h>
#include <pwd.h>
#include <grp.h>
#include <dirent.h>
Expand Down Expand Up @@ -301,7 +302,11 @@ int snprintfcat(char *dst, size_t size, const char *fmt, ...)
int ret;

size--;
assert(len <= size);
if (len > size) {
/* Do not truncate existing string */
errno = ERANGE;
return -1;
}

va_start(ap, fmt);
#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL
Expand All @@ -327,9 +332,14 @@ int snprintfcat(char *dst, size_t size, const char *fmt, ...)
* In theory it can overflow a 64-vs-32 bit range, or signed-vs-unsigned.
* In practice we hope to not have gigabytes-long config strings.
*/
assert(ret >= 0);
if (ret < 0) {
return ret;
}
#ifdef INT_MAX
assert ((unsigned long long)len < ((unsigned long long)INT_MAX - ret));
if ( ( (unsigned long long)len + (unsigned long long)ret ) >= (unsigned long long)INT_MAX ) {
errno = ERANGE;
return -1;
}
#endif
return (int)len + ret;
}
Expand Down
8 changes: 4 additions & 4 deletions common/str.c
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ int str_to_short(const char *string, short *number, const int base)
return 0;
}

*number = num;
*number = (short)num;
return 1;
}

Expand All @@ -273,7 +273,7 @@ int str_to_short_strict(const char *string, short *number, const int base)
return 0;
}

*number = num;
*number = (short)num;
return 1;
}

Expand All @@ -291,7 +291,7 @@ int str_to_ushort(const char *string, unsigned short *number, const int base)
return 0;
}

*number = num;
*number = (unsigned short)num;
return 1;
}

Expand All @@ -309,7 +309,7 @@ int str_to_ushort_strict(const char *string, unsigned short *number, const int b
return 0;
}

*number = num;
*number = (unsigned short)num;
return 1;
}

Expand Down
15 changes: 15 additions & 0 deletions common/strerror.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ char *strerror(int errnum)
{
static char buf[32];

#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE
#pragma GCC diagnostic push
#endif
#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE_BREAK
#pragma GCC diagnostic ignored "-Wunreachable-code-break"
#endif
#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE
#pragma GCC diagnostic ignored "-Wunreachable-code"
#endif

switch (errnum) {
#if defined (EPERM)
case EPERM:
Expand Down Expand Up @@ -498,6 +508,11 @@ char *strerror(int errnum)
/* Fallback: just print the error number */
snprintf(buf, sizeof(buf), "Error %d", errnum);
return buf;

#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE
#pragma GCC diagnostic pop
#endif

}

#endif /* HAVE_STRERROR */
2 changes: 1 addition & 1 deletion common/upsconf.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
static char *ups_section;

/* handle arguments separated by parseconf */
static void conf_args(int numargs, char **arg)
static void conf_args(size_t numargs, char **arg)
{
if (numargs < 1)
return;
Expand Down
17 changes: 10 additions & 7 deletions drivers/al175.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ typedef struct {
/**
* convert hex string to int
* @param head input string
* @param count string length
* @param len string length
* @return parsed value (>=0) if success, -1 on error
*/
static long from_hex(const byte_t *head, unsigned len)
Expand Down Expand Up @@ -1000,23 +1000,23 @@ typedef int VV_t; /* voltage */
#define ACT int

/* Declare to keep compiler happy even if some routines below are not used currently */
ACT TOGGLE_PRS_ONOFF ();
ACT CANCEL_BOOST ();
ACT STOP_BATTERY_TEST ();
ACT TOGGLE_PRS_ONOFF (void);
ACT CANCEL_BOOST (void);
ACT STOP_BATTERY_TEST (void);
ACT START_BATTERY_TEST (VV_t EndVolt, unsigned Minutes);
ACT SET_FLOAT_VOLTAGE (VV_t v);
ACT SET_BOOST_VOLTAGE (VV_t v);
ACT SET_HIGH_BATTERY_LIMIT (VV_t Vhigh);
ACT SET_LOW_BATTERY_LIMIT (VV_t Vlow);
ACT SET_DISCONNECT_LEVEL_AND_DELAY (VV_t level, mm_t delay);
ACT RESET_ALARMS ();
ACT CHANGE_COMM_PROTOCOL ();
ACT RESET_ALARMS (void);
ACT CHANGE_COMM_PROTOCOL (void);
ACT SET_VOLTAGE_AT_ZERO_T (VV_t v);
ACT SET_SLOPE_AT_ZERO_T (VV_t mv_per_degree);
ACT SET_MAX_TCOMP_VOLTAGE (VV_t v);
ACT SET_MIN_TCOMP_VOLTAGE (VV_t v);
ACT SWITCH_TEMP_COMP (int on);
ACT SWITCH_SYM_ALARM ();
ACT SWITCH_SYM_ALARM (void);

/* Implement */
ACT TOGGLE_PRS_ONOFF () { return al175_do(0x81, 0x80 Z3); }
Expand Down Expand Up @@ -1229,6 +1229,9 @@ void upsdrv_updateinfo(void)

}

void upsdrv_shutdown(void)
__attribute__((noreturn));

void upsdrv_shutdown(void)
{
/* TODO use TOGGLE_PRS_ONOFF for shutdown */
Expand Down
Loading