Address Coverity, Clang static analyzer warnings
* Fix type of num reliable readers (int to int32_t)
* Conversion codes in debug monitor printf formats
* Dead code elimination
* Skipping a test case where SIZE_MAX is assumed > INT32_MAX if
assumption is false on target platform
* Error handling in os_sockWaitsetNew
* Stick to unsigned in fragment size calculations
This check is actually guarded by valid_DataFrag and was safe for
datagrams up to 2GB, but the unintended and implicit conversion to is
still best eliminated.
* A "server" connection never has an invalid socket in TCP wrapper
* Handle error return from gethostname in SPDP write (CID 248183)
* Handle extended retcodes in dds_strretcode
CID 248131, introduced by 19aec98b8a
* Remove dead code in ddsrt logging test (CID 248195)
* Validate command-line argument in process test (CID 248117)
* Allow for extremely delayed store in test
Test is constructed to have the events trigger only at the appropriate
times, but it does assume that the store to cb_called becomes visible
prior to the listener callback. I'm pretty sure that will always be
the case in practice, but I'm also pretty sure there is no formal
guarantee without a memory barrier, which mutex_unlock provides.
CID 248088, 248136, 248177, 253590, 253591, 253593
* Check unsetenv return value in test (CID 248099)
Signed-off-by: Erik Boasson <eb@ilities.com>
This commit is contained in:
parent
2996a6b5f8
commit
94483e3371
23 changed files with 121 additions and 96 deletions
|
@ -10,6 +10,7 @@
|
|||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
|
||||
*/
|
||||
#include "dds/ddsrt/retcode.h"
|
||||
#include "dds/ddsrt/static_assert.h"
|
||||
|
||||
static const char *retcodes[] = {
|
||||
"Success",
|
||||
|
@ -45,6 +46,7 @@ const char *dds_strretcode (dds_return_t rc)
|
|||
{
|
||||
const dds_return_t nretcodes = (dds_return_t) (sizeof (retcodes) / sizeof (retcodes[0]));
|
||||
const dds_return_t nxretcodes = (dds_return_t) (sizeof (xretcodes) / sizeof (xretcodes[0]));
|
||||
DDSRT_STATIC_ASSERT (DDS_XRETCODE_BASE < 0);
|
||||
/* Retcodes used to be positive, but return values from the API would be a negative
|
||||
and so there are/were/may be places outside the core library where dds_strretcode
|
||||
is called with a -N for N a API return value, so ... play it safe and use the
|
||||
|
@ -53,8 +55,8 @@ const char *dds_strretcode (dds_return_t rc)
|
|||
rc = -rc;
|
||||
if (rc >= 0 && rc < nretcodes)
|
||||
return retcodes[rc];
|
||||
else if (rc >= DDS_XRETCODE_BASE && rc < DDS_XRETCODE_BASE + nxretcodes)
|
||||
return xretcodes[rc - DDS_XRETCODE_BASE];
|
||||
else if (rc >= (-DDS_XRETCODE_BASE) && rc < (-DDS_XRETCODE_BASE) + nxretcodes)
|
||||
return xretcodes[rc - (-DDS_XRETCODE_BASE)];
|
||||
else
|
||||
return "Unknown return code";
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "CUnit/Theory.h"
|
||||
#include "dds/ddsrt/environ.h"
|
||||
|
@ -49,11 +50,13 @@ CU_Test(ddsrt_environ, setenv)
|
|||
CU_ASSERT_EQUAL(rc, DDS_RETCODE_OK);
|
||||
ptr = getenv(name);
|
||||
CU_ASSERT_PTR_NOT_NULL(ptr);
|
||||
assert (ptr != NULL); /* for the benefit of clang's static analyzer */
|
||||
CU_ASSERT_STRING_EQUAL(ptr, "bar");
|
||||
/* Ensure value is copied into the environment. */
|
||||
value[2] = 'z';
|
||||
ptr = getenv(name);
|
||||
CU_ASSERT_PTR_NOT_NULL(ptr);
|
||||
assert (ptr != NULL); /* for the benefit of clang's static analyzer */
|
||||
CU_ASSERT_STRING_EQUAL(ptr, "bar");
|
||||
rc = ddsrt_setenv(name, "");
|
||||
CU_ASSERT_EQUAL(rc, DDS_RETCODE_OK);
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
*
|
||||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
|
||||
*/
|
||||
#include <assert.h>
|
||||
#include "dds/ddsrt/cdtors.h"
|
||||
#include "dds/ddsrt/ifaddrs.h"
|
||||
#include "dds/ddsrt/retcode.h"
|
||||
|
@ -73,6 +74,7 @@ CU_Test(ddsrt_getifaddrs, ipv4)
|
|||
CU_ASSERT_EQUAL_FATAL(ret, DDS_RETCODE_OK);
|
||||
for (ifa = ifa_root; ifa; ifa = ifa->next) {
|
||||
CU_ASSERT_PTR_NOT_EQUAL_FATAL(ifa->addr, NULL);
|
||||
assert (ifa->addr != NULL); /* for the benefit of clang's static analyzer */
|
||||
CU_ASSERT_EQUAL(ifa->addr->sa_family, AF_INET);
|
||||
if (ifa->addr->sa_family == AF_INET) {
|
||||
if (ifa->flags & IFF_LOOPBACK) {
|
||||
|
@ -130,6 +132,7 @@ CU_Test(ddsrt_getifaddrs, ipv6)
|
|||
CU_ASSERT_EQUAL_FATAL(ret, DDS_RETCODE_OK);
|
||||
for (ifa = ifa_root; ifa; ifa = ifa->next) {
|
||||
CU_ASSERT_PTR_NOT_EQUAL_FATAL(ifa->addr, NULL);
|
||||
assert (ifa->addr != NULL); /* for the benefit of clang's static analyzer */
|
||||
CU_ASSERT_EQUAL(ifa->addr->sa_family, AF_INET6);
|
||||
if (ifa->addr->sa_family == AF_INET6) {
|
||||
have_ipv6 = 1;
|
||||
|
@ -170,6 +173,7 @@ CU_Test(ddsrt_getifaddrs, ipv4_n_ipv6)
|
|||
CU_ASSERT_EQUAL_FATAL(ret, DDS_RETCODE_OK);
|
||||
for (ifa = ifa_root; ifa; ifa = ifa->next) {
|
||||
CU_ASSERT_PTR_NOT_EQUAL_FATAL(ifa->addr, NULL);
|
||||
assert (ifa->addr != NULL); /* for the benefit of clang's static analyzer */
|
||||
CU_ASSERT(ifa->addr->sa_family == AF_INET ||
|
||||
ifa->addr->sa_family == AF_INET6);
|
||||
if (ifa->addr->sa_family == AF_INET) {
|
||||
|
|
|
@ -254,11 +254,8 @@ CU_Test(dds_log, no_sink, .init=setup, .fini=teardown)
|
|||
ptr = NULL;
|
||||
DDS_ERROR("foobaz\n");
|
||||
ret = fseek(fh, 0, SEEK_SET);
|
||||
CU_ASSERT_EQUAL_FATAL(ret, 0);
|
||||
CU_ASSERT_PTR_NULL(ptr);
|
||||
if (ptr != NULL) {
|
||||
ddsrt_free(ptr);
|
||||
ptr = NULL;
|
||||
}
|
||||
buf[0]= '\0';
|
||||
cnt[1] = fread(buf, 1, sizeof(buf) - 1, fh);
|
||||
#ifdef _WIN32
|
||||
|
|
|
@ -29,9 +29,13 @@ static int test_sleep(int argi, int argc, char **argv)
|
|||
argi++;
|
||||
if (argi < argc) {
|
||||
long long dorment;
|
||||
ddsrt_strtoll(argv[argi], NULL, 0, &dorment);
|
||||
printf(" Process: sleep %d seconds.\n", (int)dorment);
|
||||
dds_sleepfor(DDS_SECS((int64_t)dorment));
|
||||
if (ddsrt_strtoll(argv[argi], NULL, 0, &dorment) != DDS_RETCODE_OK || dorment < 0 || dorment > INT32_MAX) {
|
||||
printf(" Process: invalid --sleep argument.\n");
|
||||
return TEST_EXIT_WRONG_ARGS;
|
||||
} else {
|
||||
printf(" Process: sleep %d seconds.\n", (int)dorment);
|
||||
dds_sleepfor(DDS_SECS((int64_t)dorment));
|
||||
}
|
||||
} else {
|
||||
printf(" Process: no --sleep value.\n");
|
||||
return TEST_EXIT_WRONG_ARGS;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue