]> granicus.if.org Git - cronie/commitdiff
anacron: fix types in comparisons
authorTomas Mraz <tmraz@fedoraproject.org>
Mon, 15 Apr 2019 08:42:11 +0000 (10:42 +0200)
committerTomas Mraz <tmraz@fedoraproject.org>
Mon, 15 Apr 2019 08:42:11 +0000 (10:42 +0200)
This fixes warnings reported by -Wsign-compare compiler option.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Tomas Mraz <tmraz@fedoraproject.org>
anacron/log.c
anacron/matchrx.c
anacron/runjob.c
src/do_command.c
src/env.c

index 2c4c8bafcab3a6fdf04dbe061361f650ff054aca..850f2ac7e46b32bb3030b9ccc5bd0b866bc084e0 100644 (file)
@@ -79,7 +79,12 @@ make_msg(const char *fmt, va_list args)
     /* There's some confusion in the documentation about what vsnprintf
      * returns when the buffer overflows.  Hmmm... */
     len = vsnprintf(msg, sizeof(msg), fmt, args);
-    if (len >= sizeof(msg) - 1)
+    if (len < 0) {
+        msg[0] = '\0';
+        strncat(msg, "(vsnprintf failed)", sizeof(msg));
+        return;
+    }
+    if ((size_t) len >= sizeof(msg) - 1)
        strcpy(msg + sizeof(msg) - sizeof(truncated), truncated);
 }
 
index e4c0d15eda12278eab8b02a6c77678e33f6c1cb3..6906fa1fbc928bfe7d497b9f1b1524ab5c9fde68 100644 (file)
@@ -42,11 +42,13 @@ match_rx(const char *rx, char *string, unsigned int n_sub,  /* char **substrings
  * This is not the most efficient, or elegant way of doing this.
  */
 {
-       int r, n;
+       int r;
+       unsigned int n;
        regex_t crx;
        va_list va;
        char **substring;
        regmatch_t *sub_offsets;
+
        sub_offsets = malloc(sizeof(regmatch_t) * (n_sub + 1));
        if (sub_offsets == NULL)
            return -1;
index 68681e4f7c36e92cc2ca13cb42a67600bf4c6cf5..a6774635d6a287a9a1ae0ec22d1d5777c155c60f 100644 (file)
@@ -53,7 +53,9 @@ temp_file(job_rec *jr)
        dir = P_tmpdir;
 
     len = snprintf(template, sizeof(template), "%s/$anacronXXXXXX", dir);
-    if (len >= sizeof(template))
+    if (len < 0)
+        die_e("snprintf failed");
+    else if ((size_t) len >= sizeof(template))
        die_e("TMPDIR too long");
 
     fdout = mkstemp(template);
index be38127b9e4f3f41e367e219fe0dea847a64f97f..a15f9be26c7d238c7ced9e2f5ce8cac9048f953c 100644 (file)
@@ -427,8 +427,14 @@ static int child_process(entry * e, char **jobenv) {
                                gethostname(hostname, MAXHOSTNAMELEN);
 
                                if (MailCmd[0] == '\0') {
-                                       if (snprintf(mailcmd, sizeof mailcmd, MAILFMT, MAILARG, mailfrom)
-                                               >= sizeof mailcmd) {
+                                       int len;
+
+                                       len = snprintf(mailcmd, sizeof mailcmd, MAILFMT, MAILARG, mailfrom);
+                                       if (len < 0) {
+                                               fprintf(stderr, "mailcmd snprintf failed\n");
+                                               (void) _exit(ERROR_EXIT);
+                                       }
+                                       if (sizeof mailcmd <= (size_t) len) {
                                                fprintf(stderr, "mailcmd too long\n");
                                                (void) _exit(ERROR_EXIT);
                                        }
index 491f6f554bb73fc7739b55a7fcc681982a5bb8ea..3336c511bb95afe843b82bda83f0452e278ee3b0 100644 (file)
--- a/src/env.c
+++ b/src/env.c
@@ -23,6 +23,7 @@
 
 #include <ctype.h>
 #include <errno.h>
+#include <stddef.h>
 #include <stdlib.h>
 #include <string.h>
 #include <sys/types.h>
@@ -281,7 +282,7 @@ char *env_get(const char *name, char **envp) {
        while ((p = *envp++) != NULL) {
                if (!(q = strchr(p, '=')))
                        continue;
-               if ((q - p) == len && !strncmp(p, name, len))
+               if ((size_t)(q - p) == len && !strncmp(p, name, len))
                        return (q + 1);
        }
        return (NULL);