]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
coverity: #1425804
authorChristian Brauner <christian.brauner@ubuntu.com>
Fri, 15 Jun 2018 09:45:12 +0000 (11:45 +0200)
committerChristian Brauner <christian.brauner@ubuntu.com>
Fri, 15 Jun 2018 10:38:14 +0000 (12:38 +0200)
Unchecked return value

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/tools/lxc_info.c

index 56af0e4fefad381ccbb7d1b9418a9e6bcd57ca8c..16d60f48da71b895219af6268806b95ea6064fce 100644 (file)
@@ -112,19 +112,19 @@ static void str_chomp(char *buf)
 static void size_humanize(unsigned long long val, char *buf, size_t bufsz)
 {
        if (val > 1 << 30) {
-               snprintf(buf, bufsz, "%u.%2.2u GiB",
-                           (unsigned int)(val >> 30),
-                           (unsigned int)(val & ((1 << 30) - 1)) / 10737419);
+               (void)snprintf(buf, bufsz, "%u.%2.2u GiB",
+                              (unsigned int)(val >> 30),
+                              (unsigned int)(val & ((1 << 30) - 1)) / 10737419);
        } else if (val > 1 << 20) {
                unsigned int x = val + 5243;  /* for rounding */
-               snprintf(buf, bufsz, "%u.%2.2u MiB",
-                           x >> 20, ((x & ((1 << 20) - 1)) * 100) >> 20);
+               (void)snprintf(buf, bufsz, "%u.%2.2u MiB", x >> 20,
+                              ((x & ((1 << 20) - 1)) * 100) >> 20);
        } else if (val > 1 << 10) {
                unsigned int x = val + 5;  /* for rounding */
-               snprintf(buf, bufsz, "%u.%2.2u KiB",
-                           x >> 10, ((x & ((1 << 10) - 1)) * 100) >> 10);
+               (void)snprintf(buf, bufsz, "%u.%2.2u KiB", x >> 10,
+                              ((x & ((1 << 10) - 1)) * 100) >> 10);
        } else {
-               snprintf(buf, bufsz, "%u bytes", (unsigned int)val);
+               (void)snprintf(buf, bufsz, "%u bytes", (unsigned int)val);
        }
 }
 
@@ -172,7 +172,10 @@ static void print_net_stats(struct lxc_container *c)
                /* XXX: tx and rx are reversed from the host vs container
                 * perspective, print them from the container perspective
                 */
-               snprintf(path, sizeof(path), "/sys/class/net/%s/statistics/rx_bytes", ifname);
+               rc = snprintf(path, sizeof(path), "/sys/class/net/%s/statistics/rx_bytes", ifname);
+               if (rc < 0 || (size_t)rc >= sizeof(path))
+                       return;
+
                rc = lxc_read_from_file(path, buf, sizeof(buf));
                if (rc > 0) {
                        str_chomp(buf);
@@ -181,7 +184,10 @@ static void print_net_stats(struct lxc_container *c)
                        fflush(stdout);
                }
 
-               snprintf(path, sizeof(path), "/sys/class/net/%s/statistics/tx_bytes", ifname);
+               rc = snprintf(path, sizeof(path), "/sys/class/net/%s/statistics/tx_bytes", ifname);
+               if (rc < 0 || (size_t)rc >= sizeof(path))
+                       return;
+
                rc = lxc_read_from_file(path, buf, sizeof(buf));
                if (rc > 0) {
                        str_chomp(buf);