]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
file_utils: fix integer comparisons
authorChristian Brauner <christian.brauner@ubuntu.com>
Fri, 3 Sep 2021 10:56:43 +0000 (12:56 +0200)
committerChristian Brauner <christian.brauner@ubuntu.com>
Fri, 3 Sep 2021 11:01:43 +0000 (13:01 +0200)
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/file_utils.c

index eaa9a5a403e2d3dd463ec34af77d357ed10324a4..f7e4fb378ea5ead35277031a01e974f4981f8d66 100644 (file)
@@ -259,14 +259,19 @@ bool file_exists(const char *f)
 int print_to_file(const char *file, const char *content)
 {
        __do_fclose FILE *f = NULL;
-       int ret = 0;
+       int ret;
+       size_t len;
 
        f = fopen(file, "we");
        if (!f)
                return -1;
 
-       if (fprintf(f, "%s", content) != strlen(content))
+       len = strlen(content);
+       ret = fprintf(f, "%s", content);
+       if (ret < 0 || (size_t)ret != len)
                ret = -1;
+       else
+               ret = 0;
 
        return ret;
 }
@@ -593,8 +598,7 @@ FILE *fdopen_at(int dfd, const char *path, const char *mode,
 int timens_offset_write(clockid_t clk_id, int64_t s_offset, int64_t ns_offset)
 {
        __do_close int fd = -EBADF;
-       int ret;
-       ssize_t len;
+       ssize_t len, ret;
        char buf[INTTYPE_TO_STRLEN(int) +
                 STRLITERALLEN(" ") + INTTYPE_TO_STRLEN(int64_t) +
                 STRLITERALLEN(" ") + INTTYPE_TO_STRLEN(int64_t) + 1];
@@ -611,7 +615,7 @@ int timens_offset_write(clockid_t clk_id, int64_t s_offset, int64_t ns_offset)
                return ret_errno(EFBIG);
 
        ret = lxc_write_nointr(fd, buf, len);
-       if (ret < 0 || (size_t)ret != len)
+       if (ret < 0 || ret != len)
                return -EIO;
 
        return 0;