From: Ruben Kerkhof Date: Mon, 5 Dec 2016 19:04:46 +0000 (+0100) Subject: Address review comments X-Git-Tag: collectd-5.8.0~285^2~1 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=f610ada7c7523e655c2d701dc2e494dcc192a7c8;p=collectd.git Address review comments --- diff --git a/contrib/docker/rootfs_prefix/rootfs_prefix.c b/contrib/docker/rootfs_prefix/rootfs_prefix.c index 65be0720..2b831518 100644 --- a/contrib/docker/rootfs_prefix/rootfs_prefix.c +++ b/contrib/docker/rootfs_prefix/rootfs_prefix.c @@ -11,20 +11,20 @@ #define BUFSIZE 256 const char *add_prefix(const char *orig, char *prefixed) { - if ((strncmp(orig, "/proc", 5) != 0) && (strncmp(orig, "/sys", 4) != 0)) + if ((strncmp(orig, "/proc", strlen("/proc")) != 0) && + (strncmp(orig, "/sys", strlen("/sys")) != 0)) return orig; int status = snprintf(prefixed, BUFSIZE, "%s%s", PREFIX, orig); - if ((unsigned int)status >= BUFSIZE) { + if (status < 1) { + error(status, errno, "adding '%s' prefix to file path failed: '%s' -> '%s'", + PREFIX, orig, prefixed); + return orig; + } else if ((unsigned int)status >= BUFSIZE) { error(status, ENAMETOOLONG, "'%s' got truncated when adding '%s' prefix: '%s'", orig, PREFIX, prefixed); return orig; - } else if (status < 1) { - error(status, errno, - "adding '%s' prefix to file path failed: '%s' -> '%s'", PREFIX, - orig, prefixed); - return orig; } else { return (const char *)prefixed; }