Fixed coverity issues

Signed-off-by: Bart Poot <bart.poot@adlinktech.com>

Processed review comments

Signed-off-by: Bart Poot <bart.poot@adlinktech.com>
This commit is contained in:
Bart Poot 2019-11-05 10:46:04 +01:00 committed by eboasson
parent c84c69e551
commit 9a3a377327
42 changed files with 168 additions and 308 deletions

View file

@ -42,10 +42,10 @@ static char *expand_env (const char *name, char op, const char *alt, expand_fn e
if ((ret = ddsrt_getenv (name, &env)) == DDS_RETCODE_OK) {
/* ok */
} else if (strcmp (name, "$") == 0 || strcmp (name, "CYCLONEDDS_PID") == 0) {
snprintf (idstr, sizeof (idstr), "%"PRIdPID, ddsrt_getpid ());
(void) snprintf (idstr, sizeof (idstr), "%"PRIdPID, ddsrt_getpid ());
env = idstr;
} else if (strcmp (name, "CYCLONEDDS_DOMAIN_ID") == 0 && domid != UINT32_MAX) {
snprintf (idstr, sizeof (idstr), "%"PRIu32, domid);
(void) snprintf (idstr, sizeof (idstr), "%"PRIu32, domid);
env = idstr;
}

View file

@ -94,7 +94,7 @@ static enum ddsrt_iftype guess_iftype (const struct ifaddrs *sys_ifa)
struct ifmediareq ifmr;
enum ddsrt_iftype type;
memset (&ifmr, 0, sizeof (ifmr));
ddsrt_strlcpy (ifmr.ifm_name, sys_ifa->ifa_name, sizeof (ifmr.ifm_name));
(void) ddsrt_strlcpy (ifmr.ifm_name, sys_ifa->ifa_name, sizeof (ifmr.ifm_name));
if (ioctl (sock, SIOCGIFMEDIA, (caddr_t) &ifmr) < 0)
{
type = DDSRT_IFTYPE_UNKNOWN;

View file

@ -54,7 +54,7 @@ static void default_sink (void *ptr, const dds_log_data_t *data)
{
if (ptr)
{
fwrite (data->message - data->hdrsize, 1, data->hdrsize + data->size + 1, (FILE *) ptr);
(void) fwrite (data->message - data->hdrsize, 1, data->hdrsize + data->size + 1, (FILE *) ptr);
fflush ((FILE *) ptr);
}
}

View file

@ -203,8 +203,8 @@ ddsrt_proc_create(
if (write(exec_fds[1], &exec_err, sizeof(int)) < (ssize_t)sizeof(int)) {
DDS_ERROR("Could not write proc error pipe.\n");
}
close(exec_fds[1]);
close(exec_fds[0]);
(void) close(exec_fds[1]);
(void) close(exec_fds[0]);
ddsrt_free(exec_argv);
_exit(1);
}
@ -214,7 +214,7 @@ ddsrt_proc_create(
/* Get execv result. */
rv = DDS_RETCODE_ERROR;
close(exec_fds[1]);
(void) close(exec_fds[1]);
nr = read(exec_fds[0], &exec_err, sizeof(int));
if (nr == 0) {
/* Pipe closed by successful execv. */
@ -228,14 +228,14 @@ ddsrt_proc_create(
rv = DDS_RETCODE_NOT_ALLOWED;
}
}
close(exec_fds[0]);
(void) close(exec_fds[0]);
if (rv == DDS_RETCODE_OK) {
/* Remember child pid. */
*pid = spawn;
} else {
/* Remove the failed fork pid from the system list. */
waitpid(spawn, NULL, 0);
(void) waitpid(spawn, NULL, 0);
}
}
@ -244,8 +244,8 @@ ddsrt_proc_create(
fail_fork:
fail_fctl:
close(exec_fds[0]);
close(exec_fds[1]);
(void) close(exec_fds[0]);
(void) close(exec_fds[1]);
fail_pipe:
ddsrt_free(exec_argv);
return rv;

View file

@ -109,7 +109,7 @@ ddsrt_getrusage_anythread (
return DDS_RETCODE_ERROR;
if ((fp = fopen (file, "r")) == NULL)
return DDS_RETCODE_NOT_FOUND;
enum { ERROR, READ_HEADING, SKIP_TO_EOL, READ_VCSW, READ_IVCSW } state = READ_HEADING;
enum { ERROR = 1, READ_HEADING, SKIP_TO_EOL, READ_VCSW, READ_IVCSW } state = READ_HEADING;
savepos = 0;
while (state != ERROR && (c = fgetc (fp)) != EOF)
{

View file

@ -126,7 +126,7 @@ ddsrt_thread_setname(const char *__restrict name)
/* Thread names are limited to 16 bytes on Linux. ERANGE is returned if the
name exceeds the limit, so silently truncate. */
char buf[MAXTHREADNAMESIZE + 1] = "";
ddsrt_strlcpy(buf, name, sizeof(buf));
(void)ddsrt_strlcpy(buf, name, sizeof(buf));
(void)pthread_setname_np(pthread_self(), name);
#elif defined(__APPLE__)
(void)pthread_setname_np(name);

View file

@ -313,7 +313,7 @@ ddsrt_thread_setname(
}
#pragma warning(pop)
}
ddsrt_strlcpy (thread_name, name, sizeof (thread_name));
(void)ddsrt_strlcpy (thread_name, name, sizeof (thread_name));
}
dds_return_t

View file

@ -459,10 +459,10 @@ static int next_token_tag_withoutclose (struct ddsrt_xmlp_state *st, char **payl
} else {
int tok = TOK_OPEN_TAG;
/* pre: peek_char(st) == '<' */
next_char (st);
(void) next_char (st);
if (peek_char (st) == '/') {
tok = TOK_CLOSE_TAG;
next_char (st);
(void) next_char (st);
}
/* we only do tag names that are identifiers */
if (peek_char (st) == '>' && (st->options & DDSRT_XMLP_ANONYMOUS_CLOSE_TAG)) {
@ -501,7 +501,7 @@ static int skip_comment (struct ddsrt_xmlp_state *st)
return 0;
}
while (peek_char (st) != TOK_EOF && (peek_char (st) != '-' || !peek_chars (st, "-->", 0))) {
next_char (st);
(void) next_char (st);
}
if (peek_chars (st, "-->", 1)) {
return 1;
@ -514,7 +514,7 @@ static void processing_instruction (struct ddsrt_xmlp_state *st, const char *end
{
/* just after <?; skip everything up to and include ?> */
while (peek_char (st) != TOK_EOF && !peek_chars (st, end, 1)) {
next_char (st);
(void) next_char (st);
}
}
@ -551,7 +551,7 @@ static int next_token (struct ddsrt_xmlp_state *st, char **payload)
st->prevline = st->line;
do {
while (qq_isspace (peek_char (st))) {
next_char (st);
(void) next_char (st);
}
} while ((cmt = skip_comment (st)) > 0);
if (cmt == TOK_ERROR) {

View file

@ -435,13 +435,13 @@ static void abort_handler (int sig)
static void abort_log (void *arg, const dds_log_data_t *info)
{
(void) arg;
ddsrt_strlcpy (abort_message, info->message, sizeof (abort_message));
(void) ddsrt_strlcpy (abort_message, info->message, sizeof (abort_message));
}
static void abort_trace (void *arg, const dds_log_data_t *info)
{
(void) arg;
ddsrt_strlcpy (abort_message_trace, info->message, sizeof (abort_message_trace));
(void) ddsrt_strlcpy (abort_message_trace, info->message, sizeof (abort_message_trace));
}
CU_TheoryDataPoints(dds_log, fatal_aborts) = {

View file

@ -157,7 +157,7 @@ CU_Test(ddsrt_sockets, gethostname)
sysbuf[0] = '\0';
#if LWIP_SOCKET
ddsrt_strlcpy(sysbuf, "localhost", sizeof(sysbuf));
(void) ddsrt_strlcpy(sysbuf, "localhost", sizeof(sysbuf));
#else
int ret = gethostname(sysbuf, sizeof(sysbuf));
CU_ASSERT_EQUAL(ret, 0);