Fix warnings reported by clang-10 static analyzer
authorPetr Štetiar <ynezz@true.cz>
Sun, 11 Oct 2020 08:45:15 +0000 (10:45 +0200)
committerPetr Štetiar <ynezz@true.cz>
Tue, 27 Oct 2020 22:03:04 +0000 (23:03 +0100)
Fixes following warnings:

 testing/include/libubox/blobmsg.h:222:67: warning: Null pointer passed to 1st parameter expecting 'nonnull'
         return blobmsg_add_field(buf, BLOBMSG_TYPE_STRING, name, string, strlen(string) + 1);
                                                                         ^~~~~~~~~~~~~~
 cgi-io/main.c:407:4: warning: Null pointer passed to 1st parameter expecting 'nonnull'
                         unlink(st.filename);
                         ^~~~~~~~~~~~~~~~~~~

 cgi-io/main.c:876:26: warning: Null pointer passed to 1st parameter expecting 'nonnull'
         size_t plen = 0, clen = strlen(cmd) + 1;
                                 ^~~~~~~~~~~

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

diff --git a/main.c b/main.c
index 549121f94488173ba3f209929e93299452414f87..64f474f9283d5943506d81ae87c76533edabf54e 100644 (file)
--- a/main.c
+++ b/main.c
@@ -109,7 +109,7 @@ session_access(const char *sid, const char *scope, const char *obj, const char *
 
        ctx = ubus_connect(NULL);
 
-       if (!ctx || ubus_lookup_id(ctx, "session", &id))
+       if (!ctx || !obj || ubus_lookup_id(ctx, "session", &id))
                goto out;
 
        blob_buf_init(&req, 0);
@@ -403,7 +403,7 @@ response(bool success, const char *message)
 
                printf("\t\"failure\": [ %u, \"%s\" ]\n", errno, strerror(errno));
 
-               if (st.filefd > -1)
+               if (st.filefd > -1 && st.filename)
                        unlink(st.filename);
        }
 
@@ -873,11 +873,16 @@ main_backup(int argc, char **argv)
 static const char *
 lookup_executable(const char *cmd)
 {
-       size_t plen = 0, clen = strlen(cmd) + 1;
+       size_t plen = 0, clen;
        static char path[PATH_MAX];
        char *search, *p;
        struct stat s;
 
+       if (!cmd)
+               return NULL;
+
+       clen = strlen(cmd) + 1;
+
        if (!stat(cmd, &s) && S_ISREG(s.st_mode))
                return cmd;