cgi-io: iron out extra compiler warnings
authorPetr Štetiar <ynezz@true.cz>
Fri, 11 Oct 2019 13:07:17 +0000 (15:07 +0200)
committerJohn Crispin <john@phrozen.org>
Fri, 11 Oct 2019 14:03:54 +0000 (16:03 +0200)
Fixes following errors:

 main.c:458:37: error: comparison of integer expressions of different signedness: ‘int’ and ‘size_t’ {aka ‘long unsigned int’} [-Werror=sign-compare]
 main.c:463:17: error: comparison of integer expressions of different signedness: ‘int’ and ‘long unsigned int’ [-Werror=sign-compare]
 main.c:518:35: error: comparison of integer expressions of different signedness: ‘ssize_t’ {aka ‘long int’} and ‘size_t’ {aka ‘long unsigned int’} [-Werror=sign-compare]
 main.c:157:3: error: ignoring return value of ‘read’, declared with attribute warn_unused_result [-Werror=unused-result]
 main.c:763:3: error: ignoring return value of ‘chdir’, declared with attribute warn_unused_result [-Werror=unused-result]

Signed-off-by: Petr Štetiar <ynezz@true.cz>
Makefile
src/main.c

index 6bc906ec5ff7116a526c14879378aaebb9f42273..92cca4fa07922d1825efba62e58cb735324b27c0 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -8,7 +8,7 @@
 include $(TOPDIR)/rules.mk
 
 PKG_NAME:=cgi-io
-PKG_RELEASE:=13
+PKG_RELEASE:=14
 
 PKG_LICENSE:=GPL-2.0-or-later
 
index e4d0b212f480c8541ec99167873616d49677433d..3530284c68754c1eafaf74f45b05e61c9cc1563c 100644 (file)
@@ -126,6 +126,7 @@ static char *
 checksum(const char *applet, size_t sumlen, const char *file)
 {
        pid_t pid;
+       int r;
        int fds[2];
        static char chksum[65];
 
@@ -154,10 +155,14 @@ checksum(const char *applet, size_t sumlen, const char *file)
 
        default:
                memset(chksum, 0, sizeof(chksum));
-               read(fds[0], chksum, sumlen);
+               r = read(fds[0], chksum, sumlen);
+
                waitpid(pid, NULL, 0);
                close(fds[0]);
                close(fds[1]);
+
+               if (r < 0)
+                       return NULL;
        }
 
        return chksum;
@@ -442,7 +447,7 @@ header_field(multipart_parser *p, const char *data, size_t len)
 static int
 header_value(multipart_parser *p, const char *data, size_t len)
 {
-       int i, j;
+       size_t i, j;
 
        if (!st.is_content_disposition)
                return 0;
@@ -500,6 +505,8 @@ data_begin_cb(multipart_parser *p)
 static int
 data_cb(multipart_parser *p, const char *data, size_t len)
 {
+       int wlen = len;
+
        switch (st.parttype)
        {
        case PART_SESSIONID:
@@ -515,14 +522,14 @@ data_cb(multipart_parser *p, const char *data, size_t len)
                break;
 
        case PART_FILEDATA:
-               if (write(st.tempfd, data, len) != len)
+               if (write(st.tempfd, data, len) != wlen)
                {
                        close(st.tempfd);
                        return response(false, "I/O failure while writing temporary file");
                }
 
                if (!st.filedata)
-                       st.filedata = !!len;
+                       st.filedata = !!wlen;
 
                break;
 
@@ -734,6 +741,7 @@ main_backup(int argc, char **argv)
 {
        pid_t pid;
        time_t now;
+       int r;
        int len;
        int status;
        int fds[2];
@@ -760,7 +768,9 @@ main_backup(int argc, char **argv)
                close(fds[0]);
                close(fds[1]);
 
-               chdir("/");
+               r = chdir("/");
+               if (r < 0)
+                       return failure(500, errno, "Failed chdir('/')");
 
                execl("/sbin/sysupgrade", "/sbin/sysupgrade",
                      "--create-backup", "-", NULL);