summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorCosta Tsaousis <costa@tsaousis.gr>2018-09-30 21:11:40 +0300
committerGitHub <noreply@github.com>2018-09-30 21:11:40 +0300
commit97ab996ec5e83a5284a38ef074ea8082347fb71a (patch)
treeca3a8e32f436b92297ac3659712795b856670450 /src
parentc33e3f75c8b9ccdb8df0df69a0d047828d27ab06 (diff)
fixes coverity identified issues (#4333)
Diffstat (limited to 'src')
-rw-r--r--src/common.c4
-rw-r--r--src/dictionary.h4
-rw-r--r--src/freeipmi_plugin.c4
-rw-r--r--src/inlined.h9
4 files changed, 15 insertions, 6 deletions
diff --git a/src/common.c b/src/common.c
index eb5c4b7268..363ae2455a 100644
--- a/src/common.c
+++ b/src/common.c
@@ -1442,7 +1442,7 @@ char *strdupz_path_subpath(const char *path, const char *subpath) {
while(len > 0 && path[len - 1] == '/') len--;
// skip leading slashes in subpath
- while(subpath && subpath[0] == '/') subpath++;
+ while(subpath[0] == '/') subpath++;
// if the last character in path is / and (there is a subpath or path is now empty)
// keep the trailing slash in path and remove the additional slash
@@ -1458,7 +1458,7 @@ char *strdupz_path_subpath(const char *path, const char *subpath) {
}
char buffer[FILENAME_MAX + 1];
- snprintfz(buffer, FILENAME_MAX, "%.*s%s%s", (int)len, path, slash, (subpath)?subpath:"");
+ snprintfz(buffer, FILENAME_MAX, "%.*s%s%s", (int)len, path, slash, subpath);
return strdupz(buffer);
}
diff --git a/src/dictionary.h b/src/dictionary.h
index c872e2a810..058aab0e03 100644
--- a/src/dictionary.h
+++ b/src/dictionary.h
@@ -1,5 +1,7 @@
// SPDX-License-Identifier: GPL-3.0-or-later
+#include "common.h"
+
#ifndef NETDATA_DICTIONARY_H
#define NETDATA_DICTIONARY_H 1
@@ -37,7 +39,7 @@ typedef struct dictionary {
extern DICTIONARY *dictionary_create(uint8_t flags);
extern void dictionary_destroy(DICTIONARY *dict);
-extern void *dictionary_set(DICTIONARY *dict, const char *name, void *value, size_t value_len);
+extern void *dictionary_set(DICTIONARY *dict, const char *name, void *value, size_t value_len) NEVERNULL;
extern void *dictionary_get(DICTIONARY *dict, const char *name);
extern int dictionary_del(DICTIONARY *dict, const char *name);
diff --git a/src/freeipmi_plugin.c b/src/freeipmi_plugin.c
index ad4dda139c..899a63d6fe 100644
--- a/src/freeipmi_plugin.c
+++ b/src/freeipmi_plugin.c
@@ -1529,8 +1529,8 @@ int main (int argc, char **argv) {
int i, freq = 0;
for(i = 1; i < argc ; i++) {
if(isdigit(*argv[i]) && !freq) {
- int n = atoi(argv[i]);
- if(n > 0 && freq < 86400) {
+ int n = str2i(argv[i]);
+ if(n > 0 && n < 86400) {
freq = n;
continue;
}
diff --git a/src/inlined.h b/src/inlined.h
index bd63271bfc..591b5adb08 100644
--- a/src/inlined.h
+++ b/src/inlined.h
@@ -1,5 +1,7 @@
// SPDX-License-Identifier: GPL-3.0-or-later
+#include "common.h"
+
#ifndef NETDATA_INLINED_H
#define NETDATA_INLINED_H 1
@@ -245,12 +247,17 @@ static inline char *strncpyz(char *dst, const char *src, size_t n) {
}
static inline int read_file(const char *filename, char *buffer, size_t size) {
+ if(unlikely(!size)) return 3;
+
int fd = open(filename, O_RDONLY, 0666);
- if(unlikely(fd == -1))
+ if(unlikely(fd == -1)) {
+ buffer[0] = '\0';
return 1;
+ }
ssize_t r = read(fd, buffer, size);
if(unlikely(r == -1)) {
+ buffer[0] = '\0';
close(fd);
return 2;
}