Fix signed/unsigned types
authorJose Bollo <jose.bollo@iot.bzh>
Wed, 9 Oct 2019 12:10:22 +0000 (14:10 +0200)
committerJosé Bollo <jose.bollo@iot.bzh>
Thu, 10 Oct 2019 13:25:50 +0000 (15:25 +0200)
Signed-off-by: Jose Bollo <jose.bollo@iot.bzh>
CMakeLists.txt
compat/src/main-test-old-cynara.c
src/cyn-server.c
src/expire.c
src/filedb.c
src/main-cynagorad.c
src/main-cynagoradm.c
src/socket.c

index aeb3a53..2995a07 100644 (file)
@@ -58,7 +58,6 @@ link_libraries(-Wl,--as-needed -Wl,--gc-sections -Wl,--no-undefined)
 
 add_compile_options(-Wall -Wextra -Wconversion)
 add_compile_options(-Wno-unused-parameter) # frankly not using a parameter does it care?
-add_compile_options(-Wno-sign-compare -Wno-sign-conversion)
 add_compile_options(-Werror=maybe-uninitialized)
 add_compile_options(-Werror=implicit-function-declaration)
 add_compile_options(-ffunction-sections -fdata-sections)
index ccc3baa..f5f58ba 100644 (file)
@@ -43,7 +43,7 @@ struct cynara_async *aclient;
 struct cynara_configuration *conf;
 struct cynara *client;
 char buffer[4000];
-int bufill;
+size_t bufill;
 char *str[40];
 int nstr;
 int pollfd;
@@ -124,10 +124,10 @@ void adm_check(char *cli, char *usr, char *perm)
 void adm_set()
 {
        struct cynara_admin_policy **policies, *p;
-       int n, i;
+       unsigned n, i;
 
-       n = (nstr - 2) / 4;
-       policies = malloc((1 + n) * sizeof *policies + n * sizeof **policies);
+       n = (unsigned)((nstr - 2) / 4);
+       policies = malloc((1 + n) * (sizeof *policies) + n * sizeof **policies);
        policies[n] = NULL;
        p = (struct cynara_admin_policy*)(&policies[n + 1]);
        for (i = 0 ; i < n ; i++, p++) {
@@ -275,12 +275,11 @@ int main(int ac, char **av)
 
                if (ev.data.fd == 0) {
                        if (ev.events & EPOLLIN) {
-                               rc = (int)sizeof buffer - bufill;
-                               rc = (int)read(0, buffer, rc);
+                               rc = (int)read(0, buffer, sizeof buffer - bufill);
                                if (rc == 0)
                                        break;
                                if (rc > 0) {
-                                       bufill += rc;
+                                       bufill += (size_t)rc;
                                        while((p = memchr(buffer, '\n', bufill))) {
                                                /* process one line */
                                                *p++ = 0;
@@ -290,7 +289,7 @@ int main(int ac, char **av)
                                                if (action())
                                                        goto terminate;
                                                /* next line if any */
-                                               bufill -= (int)(p - buffer);
+                                               bufill -= (size_t)(p - buffer);
                                                if (!bufill)
                                                        break;
                                                memmove(buffer, p, bufill);
index d751fda..78143a4 100644 (file)
@@ -120,13 +120,13 @@ void
 dolog(
        client_t *cli,
        int c2s,
-       int count,
+       unsigned count,
        const char *fields[]
 ) {
        static const char types[3][6] = { "check", "agent", "admin" };
        static const char dir[2] = { '>', '<' };
 
-       int i;
+       unsigned i;
 
        fprintf(stderr, "%p%c%c%s", cli, dir[!c2s], dir[!c2s], types[cli->type]);
        for (i = 0 ; i < count ; i++)
@@ -354,7 +354,7 @@ static
 void
 onrequest(
        client_t *cli,
-       int count,
+       unsigned count,
        const char *args[]
 ) {
        bool nextlog;
@@ -565,7 +565,7 @@ on_client_event(
                        goto terminate;
                nargs = prot_get(cli->prot, &args);
                while (nargs >= 0) {
-                       onrequest(cli, nargs, args);
+                       onrequest(cli, (unsigned)nargs, args);
                        if (cli->invalid && !cli->relax)
                                goto terminate;
                        prot_next(cli->prot);
index cfa5dff..23ce6ae 100644 (file)
@@ -76,7 +76,7 @@ size_t exp2txt(time_t expire, char *buffer, size_t buflen)
                n = 0;
 #define ADD(C,U) \
   if (expire >= U) { \
-    n += snprintf(&b[n], sizeof b - n, "%lld" #C, (long long)(expire / U)); \
+    n += snprintf(&b[n], sizeof b - (size_t)n, "%lld" #C, (long long)(expire / U)); \
     expire %= U; \
   }
                ADD(y,YEAR)
index 86c302d..1fa5087 100644 (file)
@@ -95,7 +95,7 @@ static const char uuid_names_v1[] = "b2c33494-995f-5cc2-9e5e-72ad412936a9\n--\n"
 static const char uuid_rules_v1[] = "73630c61-89a9-5e82-8b07-5e53eee785c8\n--\n";
 
 /** length of the identifications */
-static const int uuidlen = 40;
+static const uint32_t uuidlen = 40;
 
 
 struct filedb
index 66b5ea7..db5408d 100644 (file)
@@ -276,8 +276,8 @@ int main(int ac, char **av)
                                fprintf(stderr, "can not find user '%s'\n", user);
                                return -1;
                        }
-                       uid = pw->pw_uid;
-                       gid = pw->pw_gid;
+                       uid = (int)pw->pw_uid;
+                       gid = (int)pw->pw_gid;
                }
        }
        if (group) {
@@ -288,7 +288,7 @@ int main(int ac, char **av)
                                fprintf(stderr, "can not find group '%s'\n", group);
                                return -1;
                        }
-                       gid = gr->gr_gid;
+                       gid = (int)gr->gr_gid;
                }
        }
 
@@ -300,14 +300,14 @@ int main(int ac, char **av)
 
        /* drop privileges */
        if (gid >= 0) {
-               rc = setgid(gid);
+               rc = setgid((gid_t)gid);
                if (rc < 0) {
                        fprintf(stderr, "can not change group: %m\n");
                        return -1;
                }
        }
        if (uid >= 0) {
-               rc = setuid(uid);
+               rc = setuid((uid_t)uid);
                if (rc < 0) {
                        fprintf(stderr, "can not change user: %m\n");
                        return -1;
@@ -414,8 +414,8 @@ static void ensuredir(char *path, int length, int uid, int gid)
                                        exit(1);
                                }
                                /* set ownership */
-                               if ((uid != st.st_uid && uid >= 0) || (gid != st.st_gid && gid >= 0)) {
-                                       rc = chown(path, uid, gid);
+                               if (((uid_t)uid != st.st_uid && uid >= 0) || ((gid_t)gid != st.st_gid && gid >= 0)) {
+                                       rc = chown(path, (uid_t)uid, (gid_t)gid);
                                        if (rc < 0) {
                                                fprintf(stderr, "can not own directory %s for uid=%d & gid=%d: %m\n", path, uid, gid);
                                                exit(1);
index 7b657c0..b668abb 100644 (file)
@@ -303,7 +303,7 @@ help_expiration_text[] =
 
 static cynagora_t *cynagora;
 static char buffer[4000];
-static int bufill;
+static size_t bufill;
 static char *str[40];
 static int nstr;
 static int pending;
@@ -789,12 +789,11 @@ int main(int ac, char **av)
        for(;;) {
                rc = poll(fds, 2, -1);
                if (fds[0].revents & POLLIN) {
-                       rc = (int)sizeof buffer - bufill;
-                       rc = (int)read(0, buffer, rc);
+                       rc = (int)read(0, buffer, sizeof buffer - bufill);
                        if (rc == 0)
                                break;
                        if (rc > 0) {
-                               bufill += rc;
+                               bufill += (size_t)rc;
                                while((p = memchr(buffer, '\n', bufill))) {
                                        /* process one line */
                                        *p++ = 0;
@@ -802,7 +801,7 @@ int main(int ac, char **av)
                                        while(str[nstr])
                                                str[++nstr] = strtok(NULL, " \t");
                                        do_all(nstr, str);
-                                       bufill -= (int)(p - buffer);
+                                       bufill -= (size_t)(p - buffer);
                                        if (!bufill)
                                                break;
                                        memmove(buffer, p, bufill);
index bd6b804..fde9648 100644 (file)
@@ -168,8 +168,8 @@ static int open_tcp(const char *spec, int server)
                errno = EINVAL;
                return -1;
        }
-       host = strndupa(spec, service++ - spec);
-       service = strndupa(service, tail - service);
+       host = strndupa(spec, (size_t)(service++ - spec));
+       service = strndupa(service, (size_t)(tail - service));
 
        /* get addr */
        memset(&hint, 0, sizeof hint);
@@ -256,7 +256,7 @@ static struct entry *get_entry(const char *uri, int *offset)
                }
                i--;
                l = (int)strlen(entries[i].prefix);
-               if (!strncmp(uri, entries[i].prefix, l))
+               if (!strncmp(uri, entries[i].prefix, (size_t)l))
                        break;
        }