Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A little bit of Fightwarn #2096

Merged
merged 30 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
37e01e0
Jenkinsfile-dynamatrix: default a MAKE=make envvar if somehow missing…
jimklimov Oct 2, 2023
c61bfc3
Jenkinsfile-dynamatrix: default a MAKE=make envvar if somehow missing…
jimklimov Oct 2, 2023
6f5b491
tests/generic_gpio_utest.c: fix warnings about formatting strings
jimklimov Oct 3, 2023
436ef40
common/common.c: fix casting warnings
jimklimov Oct 3, 2023
0d54fb7
clients/upssched.c: fix casting warnings
jimklimov Oct 3, 2023
19245e5
drivers/dummy-ups.c: fix casting warnings
jimklimov Oct 3, 2023
2a05d51
drivers/main.c: fix portability of chown() used as chgrp()
jimklimov Oct 3, 2023
2b640e3
drivers/main.c: fix indentation
jimklimov Oct 3, 2023
2bcb703
drivers/main.c: fix cmdret=upsdrvquery_oneshot() as a generally ssize…
jimklimov Oct 3, 2023
16a5c27
drivers/upsdrvquery.c: fix casting warnings
jimklimov Oct 3, 2023
858f5ff
drivers/clone.c: fix casting warnings
jimklimov Oct 3, 2023
e502c2e
Add a fallback inet_ntop() implementation
jimklimov Oct 3, 2023
717a4f3
drivers/apcupsd-ups.c: port bits of poll.h to have this buildable on …
jimklimov Oct 3, 2023
a0ab721
include/wincompat.h: comment correct portable arg type for inet_ntop()
jimklimov Oct 4, 2023
5d1236b
m4/ax_run_or_link_ifelse.m4: make more effort to detect undefined-nes…
jimklimov Oct 4, 2023
6aed0ee
configure.ac: detect availability of struct pollfd
jimklimov Oct 4, 2023
5138855
drivers/apcupsd-ups.c: use detected availability of struct pollfd to …
jimklimov Oct 4, 2023
7632ef3
tests/generic_gpio_utest.c: more fscanf() width warnings
jimklimov Oct 6, 2023
dfbf5e9
Jenkinsfile-dynamatrix: enable tracing for fightwarn branches
jimklimov Oct 6, 2023
ba9d3da
Jenkinsfile-dynamatrix: warn about lack of dynacfgPipeline.configureE…
jimklimov Oct 7, 2023
9b98822
tests/generic_gpio_utest.c: avoid NULL deref in printf() on some plat…
jimklimov Oct 7, 2023
a457355
Jenkinsfile-dynamatrix: hush down groovy debug verbosity, use BRANCH_…
jimklimov Oct 8, 2023
d78fea9
Merge branch 'master' into fightwarn
jimklimov Oct 8, 2023
935fef2
drivers/main.c: follow TOCTOU analysis suggestions about file permiss…
jimklimov Oct 8, 2023
4fd257e
tests/nutlogtest.c: revise include statements
jimklimov Oct 9, 2023
1aaff29
tests/Makefile.am: refer to nutlogtest$(EXEEXT) for clarity in depend…
jimklimov Oct 9, 2023
a816677
data/driver.list.in: add CP1350PFCLCD
jimklimov Oct 10, 2023
1a153ec
tests/generic_gpio_utest.c: avoid "error: variable might be clobbered…
jimklimov Oct 10, 2023
a55bcd3
tests/generic_gpio_utest.c: cosmetic fixes
jimklimov Oct 10, 2023
ce37a62
clients/upsclient.c, server/netssl.c, m4/ax_c_pragmas.m4: hush -Wcast…
jimklimov Oct 10, 2023
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
36 changes: 25 additions & 11 deletions Jenkinsfile-dynamatrix
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,16 @@ import org.nut.dynamatrix.*;
dynacfgPipeline.disableSlowBuildCIBuild_QEMU = false
}

dynacfgPipeline.traceBuildShell_configureEnvvars = false// true
dynacfgPipeline.traceBuildShell = false //true
dynacfgPipeline.traceBuildShell_configureEnvvars = false // true
dynacfgPipeline.traceBuildShell = false // true

//if (false) // <<< (Un-)comment away in select runs/branches
//if (true) // <<< (Un-)comment away in select runs/branches
if ( env?.BRANCH_NAME ==~ /.*fightwarn-verbose.*/ )
{
dynacfgPipeline.traceBuildShell_configureEnvvars = true // false
dynacfgPipeline.traceBuildShell = true // false
}

dynacfgPipeline.failFast = //true //
false
Expand Down Expand Up @@ -98,7 +106,7 @@ import org.nut.dynamatrix.*;
//'stageNameFunc': null,
//'dynamatrixAxesLabels': [~/^OS_.+/, 'MAKE'],
'dynamatrixAxesLabels': ['OS_FAMILY', 'OS_DISTRO', 'MAKE'],
'single': '( \${MAKE} shellcheck )',
'single': '( if [ x"\${MAKE-}" = x ]; then echo "WARNING: MAKE is somehow unset, defaulting!" >&2; MAKE=make; fi; \${MAKE} shellcheck )',
'multi': '(cd tests && SERVICE_FRAMEWORK="selftest" SHELL_PROGS="$SHELL_PROGS" ./nut-driver-enumerator-test.sh )',
'multiLabel': 'SHELL_PROGS',
'skipShells': [ 'zsh', 'tcsh', 'csh' ]
Expand Down Expand Up @@ -233,7 +241,10 @@ import org.nut.dynamatrix.*;
if (!dynacfgPipeline.containsKey('buildPhases')) {
dynacfgPipeline.buildPhases = [:]
}
dynacfgPipeline.buildPhases['distcheck'] = """( eval \${CONFIG_ENVVARS} time \${MAKE} \${MAKE_OPTS} distcheck DISTCHECK_FLAGS="\${CONFIG_OPTS}" )"""

// Imported from jenkins-dynamatrix JSL vars/autotools.groovy:
// a workaround for the cases of curiously missing MAKE envvar...
dynacfgPipeline.buildPhases['distcheck'] = """( if [ x"\${MAKE-}" = x ]; then echo "WARNING: MAKE is somehow unset, defaulting!" >&2; MAKE=make; fi; eval \${CONFIG_ENVVARS} time \${MAKE} \${MAKE_OPTS} distcheck DISTCHECK_FLAGS="\${CONFIG_OPTS}" )"""

// Note: shellcheck/spellcheck/... require autotools currently
// or need to be redefined with respective BUILD_TYPE
Expand All @@ -246,7 +257,8 @@ import org.nut.dynamatrix.*;
def dsbcClone = dsbc.clone()

stage('Investigate envvars (Autotools DEBUG)') {
echo "Running default custom build for '${stageNameClone}' ==> ${dsbcClone.toString()}"
echo "Running default custom build for '${stageNameClone}' ==> ${dsbcClone.toString()}" +
(dynacfgPipeline?.configureEnvvars ? "" : " (note: has no dynacfgPipeline.configureEnvvars)")
// Trick about endianness via ELF binary header picked up from https://serverfault.com/a/749469/490516
sh label: 'Inspect initial envvars', script: """ hostname; date -u; uname -a
echo "LONG_BIT:`getconf LONG_BIT` WORD_BIT:`getconf WORD_BIT`" || true
Expand Down Expand Up @@ -275,7 +287,8 @@ set | sort -n """
def dsbcClone = dsbc.clone()

stage('Investigate envvars (CI_Build DEBUG)') {
echo "Running default custom build for '${stageNameClone}' ==> ${dsbcClone.toString()}"
echo "Running default custom build for '${stageNameClone}' ==> ${dsbcClone.toString()}" +
(dynacfgPipeline?.configureEnvvars ? "" : " (note: has no dynacfgPipeline.configureEnvvars)")
// Trick about endianness via ELF binary header picked up from https://serverfault.com/a/749469/490516
sh label: 'Inspect initial envvars', script: """ hostname; date -u; uname -a
echo "LONG_BIT:`getconf LONG_BIT` WORD_BIT:`getconf WORD_BIT`" || true
Expand Down Expand Up @@ -1263,14 +1276,15 @@ def stageNameFunc_ShellcheckCustom(DynamatrixSingleBuildConfig dsbc) {

///////////////////////////////////////////////////////////////////////////

// Hacky big switch for a max debug option
if (true)
if (false)
{
// Hacky big switch for a max debug option
//if (true) // <<< (Un-)comment away in select runs/branches
//if (false) // <<< (Un-)comment away in select runs/branches
if ( env?.BRANCH_NAME ==~ /.*verbose.*/ )
{
dynamatrixGlobalState.enableDebugTrace = true
dynamatrixGlobalState.enableDebugErrors = true
dynamatrixGlobalState.enableDebugMilestones = true
dynamatrixGlobalState.enableDebugMilestonesDetails = true
}
}

dynamatrixPipeline(dynacfgBase, dynacfgPipeline)
7 changes: 7 additions & 0 deletions clients/upsclient.c
Original file line number Diff line number Diff line change
Expand Up @@ -909,6 +909,10 @@ static int upscli_sslinit(UPSCONN_t *ups, int verifycert)
return -1;
}

#if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP) && (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_CAST_FUNCTION_TYPE_STRICT)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wcast-function-type-strict"
#endif
if (verifycert) {
status = SSL_AuthCertificateHook(ups->ssl,
(SSLAuthCertificate)AuthCertificate, CERT_GetDefaultCertDB());
Expand Down Expand Up @@ -938,6 +942,9 @@ static int upscli_sslinit(UPSCONN_t *ups, int verifycert)
nss_error("upscli_sslinit / SSL_HandshakeCallback");
return -1;
}
#if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP) && (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_CAST_FUNCTION_TYPE_STRICT)
#pragma GCC diagnostic pop
#endif

cert = upscli_find_host_cert(ups->host);
if (cert != NULL && cert->certname != NULL) {
Expand Down
2 changes: 1 addition & 1 deletion clients/upssched.c
Original file line number Diff line number Diff line change
Expand Up @@ -959,7 +959,7 @@ static void start_daemon(TYPE_FD lockfd)
if (d > 0 && d < 0.2) {
d = (1.0 - d) * 1000000.0;
upsdebugx(5, "Enforcing a throttling sleep: %f usec", d);
usleep(d);
usleep((useconds_t)d);
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions common/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@ double difftimeval(struct timeval x, struct timeval y)
result.tv_sec = x.tv_sec - y.tv_sec;
result.tv_usec = x.tv_usec - y.tv_usec;

d = 0.000001 * result.tv_usec + result.tv_sec;
d = 0.000001 * (double)(result.tv_usec) + (double)(result.tv_sec);
return d;
}

Expand Down Expand Up @@ -718,7 +718,7 @@ static usec_t timespec_load(const struct timespec *ts) {
if (ts->tv_sec < 0 || ts->tv_nsec < 0)
return USEC_INFINITY;

if ((usec_t) ts->tv_sec > (UINT64_MAX - (ts->tv_nsec / NSEC_PER_USEC)) / USEC_PER_SEC)
if ((usec_t) ts->tv_sec > (UINT64_MAX - ((uint64_t)(ts->tv_nsec) / NSEC_PER_USEC)) / USEC_PER_SEC)
return USEC_INFINITY;

return
Expand Down Expand Up @@ -767,7 +767,7 @@ double difftimespec(struct timespec x, struct timespec y)
result.tv_sec = x.tv_sec - y.tv_sec;
result.tv_nsec = x.tv_nsec - y.tv_nsec;

d = 0.000000001 * result.tv_nsec + result.tv_sec;
d = 0.000000001 * (double)(result.tv_nsec) + (double)(result.tv_sec);
return d;
}
#endif /* HAVE_CLOCK_GETTIME && HAVE_CLOCK_MONOTONIC */
Expand Down Expand Up @@ -1265,7 +1265,7 @@ static void vupslog(int priority, const char *fmt, va_list va, int use_strerror)
if (((uintmax_t)ret) > (SIZE_MAX - LARGEBUF)) {
goto vupslog_too_long;
}
newbufsize = ret + LARGEBUF;
newbufsize = (size_t)ret + LARGEBUF;
} /* else: errno, e.g. ERANGE printing:
* "...(34 => Result too large)" */
if (nut_debug_level > 0) {
Expand Down
190 changes: 188 additions & 2 deletions common/wincompat.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,17 @@
#include "wincompat.h"
#include "nut_stdint.h"

#if ! HAVE_INET_PTON
# include <string.h>
# include <ctype.h>
# if HAVE_WINSOCK2_H
# include <winsock2.h>
# endif
# if HAVE_WS2TCPIP_H
# include <ws2tcpip.h>
# endif
#endif

#if (0)
extern int errno;
#endif
Expand Down Expand Up @@ -204,6 +215,181 @@ const char* inet_ntop(int af, const void* src, char* dst, size_t cnt)
}
#endif /* HAVE_INET_NTOP */

#if ! HAVE_INET_PTON
/* Fallback implementation of inet_pton() for systems that lack it,
* such as older versions of Windows (including MinGW builds that do
* not specifically target _WIN32_WINNT or newer).
*
* Based on code attributed to Paul Vixie, 1996,
* sourced from https://stackoverflow.com/a/15370175/4715872
*/

#define NS_INADDRSZ sizeof(struct in_addr) /* 4 */
#define NS_IN6ADDRSZ sizeof(struct in6_addr) /* 16 */
#define NS_INT16SZ sizeof(uint16_t) /* 2 */

static int inet_pton4(const char *src, void *dst)
{
uint8_t tmp[NS_INADDRSZ], *tp; /* for struct in_addr *dst */

int saw_digit = 0;
int octets = 0;
int ch;

*(tp = tmp) = 0;

while ((ch = *src++) != '\0')
{
if (ch >= '0' && ch <= '9')
{
uint32_t n = *tp * 10 + (ch - '0');

if (saw_digit && *tp == 0)
return 0;

if (n > 255)
return 0;

*tp = n;
if (!saw_digit)
{
if (++octets > 4)
return 0;
saw_digit = 1;
}
}
else if (ch == '.' && saw_digit)
{
if (octets == 4)
return 0;
*++tp = 0;
saw_digit = 0;
}
else
return 0;
}
if (octets < 4)
return 0;

memcpy(dst, tmp, NS_INADDRSZ);

return 1;
}

static int inet_pton6(const char *src, void *dst)
{
static const char xdigits[] = "0123456789abcdef";
uint8_t tmp[NS_IN6ADDRSZ]; /* for struct in6_addr *dst */

uint8_t *tp = (uint8_t*) memset(tmp, '\0', NS_IN6ADDRSZ);
uint8_t *endp = tp + NS_IN6ADDRSZ;
uint8_t *colonp = NULL;

const char *curtok = NULL;
int saw_xdigit = 0;
uint32_t val = 0;
int ch;

/* Leading :: requires some special handling. */
if (*src == ':')
{
if (*++src != ':')
return 0;
}

curtok = src;

while ((ch = tolower(*src++)) != '\0')
{
const char *pch = strchr(xdigits, ch);
if (pch != NULL)
{
val <<= 4;
val |= (pch - xdigits);
if (val > 0xffff)
return 0;
saw_xdigit = 1;
continue;
}
if (ch == ':')
{
curtok = src;
if (!saw_xdigit)
{
if (colonp)
return 0;
colonp = tp;
continue;
}
else if (*src == '\0')
{
return 0;
}
if (tp + NS_INT16SZ > endp)
return 0;
*tp++ = (uint8_t) (val >> 8) & 0xff;
*tp++ = (uint8_t) val & 0xff;
saw_xdigit = 0;
val = 0;
continue;
}
if (ch == '.' && ((tp + NS_INADDRSZ) <= endp) &&
inet_pton4(curtok, (char*) tp) > 0)
{
tp += NS_INADDRSZ;
saw_xdigit = 0;
break; /* '\0' was seen by inet_pton4(). */
}
return 0;
}
if (saw_xdigit)
{
if (tp + NS_INT16SZ > endp)
return 0;
*tp++ = (uint8_t) (val >> 8) & 0xff;
*tp++ = (uint8_t) val & 0xff;
}
if (colonp != NULL)
{
/*
* Since some memmove()'s erroneously fail to handle
* overlapping regions, we'll do the shift by hand.
*/
const int n = tp - colonp;
int i;

if (tp == endp)
return 0;

for (i = 1; i <= n; i++)
{
endp[-i] = colonp[n - i];
colonp[n - i] = 0;
}
tp = endp;
}
if (tp != endp)
return 0;

memcpy(dst, tmp, NS_IN6ADDRSZ);

return 1;
}

int inet_pton(int af, const char *src, void *dst)
{
switch (af)
{
case AF_INET:
return inet_pton4(src, dst);
case AF_INET6:
return inet_pton6(src, dst);
default:
return -1;
}
}
#endif /* ! HAVE_INET_PTON */

/* "system" call seems to handle path with blank name incorrectly */
int win_system(const char * command)
{
Expand Down Expand Up @@ -1448,9 +1634,9 @@ speed_t cfgetospeed(const struct termios *t)
return t->c_ospeed;
}

#else
#else /* !WIN32 */

/* Just avoid: ISO C forbids an empty translation unit [-Werror=pedantic] */
int main (int argc, char ** argv);

#endif
#endif /* WIN32 */
Loading
Loading