]> granicus.if.org Git - cronie/commitdiff
Use proper variable types.
authorTomas Mraz <tmraz@fedoraproject.org>
Thu, 14 Sep 2017 11:56:20 +0000 (13:56 +0200)
committerTomas Mraz <tmraz@fedoraproject.org>
Thu, 14 Sep 2017 11:56:20 +0000 (13:56 +0200)
16 files changed:
anacron/global.h
anacron/main.c
anacron/matchrx.c
anacron/matchrx.h
anacron/readtab.c
src/bitstring.h
src/cron.c
src/cronnext.c
src/crontab.c
src/database.c
src/do_command.c
src/entry.c
src/env.c
src/funcs.h
src/misc.c
src/popen.c

index 9d5ef76c1e09329e28d3261fd21c75097295a133..18568543690ce33922b3832acafabbf86cfb2996 100644 (file)
@@ -68,7 +68,7 @@ struct job_rec1 {
    int timestamp_fd;
    int input_fd;
    int output_fd;
-   int mail_header_size;
+   off_t mail_header_size;
    pid_t job_pid;
    pid_t mailer_pid;
    int drop_job;
index 58d1b567c846351a16759ac6e4bb3a8cb8b70bbe..d0929705555e112eee0036bed02fd1c77e6d1104 100644 (file)
@@ -372,17 +372,17 @@ record_start_time(void)
                year, month, day_of_month);
 }
 
-static int
+static unsigned int
 time_till(job_rec *jr)
 /* Return the number of seconds that we have to wait until it's time
  * to start job jr.
  */
 {
-    unsigned int tj, tn;
+    time_t tj, tn;
 
     if (now) return 0;
     tn = time(NULL);
-    tj = start_sec + jr->delay * 60;
+    tj = start_sec + (time_t)jr->delay * 60;
     if (tj < tn) return 0;
     if (tj - tn > 3600*24)
     {
@@ -390,7 +390,7 @@ time_till(job_rec *jr)
            jr->ident);
        return 0;
     }
-    return tj - tn;
+    return (unsigned int)(tj - tn);
 }
 
 static void
@@ -447,7 +447,7 @@ main(int argc, char *argv[])
     if (gettimeofday(&tv, &tz) != 0)
         explain("Can't get exact time, failure.");
 
-    srandom(getpid()+tv.tv_usec);
+    srandom((unsigned int)(getpid() + tv.tv_usec));
 
     if((program_name = strrchr(argv[0], '/')) == NULL)
        program_name = argv[0];
index 274672c215241fc6b7fea9f1ffcbba9108a4f9fe..e4c0d15eda12278eab8b02a6c77678e33f6c1cb3 100644 (file)
@@ -30,7 +30,7 @@
 #include "matchrx.h"
 
 int
-match_rx(const char *rx, char *string, int n_sub,  /* char **substrings */...)
+match_rx(const char *rx, char *string, unsigned int n_sub,  /* char **substrings */...)
 /* Return 1 if the regular expression "*rx" matches the string "*string",
  * 0 if not, -1 on error.
  * "Extended" regular expressions are used.
index b8028482f33530deaf6c2faac25084d3481360b0..d5f3273506ce1f3299bca6cc3ed4dd02d4346e52 100644 (file)
@@ -23,4 +23,4 @@
 
 
 int match_rx(const char *rx, char *string,
-            int n_sub, /* char **substrings */...);
+            unsigned int n_sub, /* char **substrings */...);
index 51b27eafc54edea3e61816726c4a6453c654c74d..e4da32d7d6beb173183f910292ae0f2360e53dc7 100644 (file)
@@ -77,7 +77,7 @@ conv2int(const char *s)
     l = strtol(s, NULL, 10);
     /* we use negative as error, so I am really returning unsigned int */
     if (errno == ERANGE || l < 0 || l > INT_MAX) return - 1;
-    return l;
+    return (int)l;
 }
 
 static char *
@@ -94,11 +94,11 @@ Return NULL if no more lines.
        c = getc(tab);
        if ((c == '\n' && prev != '\\') || c == EOF)
        {
-           if (0 != prev) obstack_1grow(&input_o, prev);
+           if (0 != prev) obstack_1grow(&input_o, (char)prev);
            break;
        }
 
-       if ('\\' != prev && 0 != prev && '\n' != prev) obstack_1grow(&input_o, prev);
+       if ('\\' != prev && 0 != prev && '\n' != prev) obstack_1grow(&input_o, (char)prev);
        else if ('\n' == prev) obstack_1grow(&input_o, ' ');
 
        prev = c;
@@ -132,8 +132,8 @@ register_env(const char *env_var, const char *value)
     env_rec *er;
     int var_len, val_len;
 
-    var_len = strlen(env_var);
-    val_len = strlen(value);
+    var_len = (int)strlen(env_var);
+    val_len = (int)strlen(value);
     er = obstack_alloc(&tab_o, sizeof(env_rec));
     er->assign = obstack_alloc(&tab_o, var_len + 1 + val_len + 1);
     strcpy(er->assign, env_var);
@@ -155,8 +155,8 @@ register_job(const char *periods, const char *delays,
     job_rec *jr;
     int ident_len, command_len;
 
-    ident_len = strlen(ident);
-    command_len = strlen(command);
+    ident_len = (int)strlen(ident);
+    command_len = (int)strlen(command);
     jobs_read++;
     period = conv2int(periods);
     delay = conv2int(delays);
@@ -196,8 +196,8 @@ register_period_job(const char *periods, const char *delays,
     job_rec *jr;
     int ident_len, command_len;
 
-    ident_len = strlen(ident);
-    command_len = strlen(command);
+    ident_len = (int)strlen(ident);
+    command_len = (int)strlen(command);
     jobs_read++;
     delay = conv2int(delays);
     if (delay < 0)
@@ -417,6 +417,6 @@ arrange_jobs(void)
     job_array = obstack_finish(&tab_o);
 
     /* sort the jobs */
-    qsort(job_array, njobs, sizeof(*job_array),
+    qsort(job_array, (size_t)njobs, sizeof(*job_array),
          (int (*)(const void *, const void *))execution_order);
 }
index 43bd8433afd61ade1909f451ef8048d99e2aacf4..0c41a836e47b7423761bd87c0ee62d62ab8a999e 100644 (file)
@@ -68,11 +68,11 @@ typedef     unsigned char bitstr_t;
 
                                /* set bit N of bitstring name */
 #define        bit_set(name, bit) \
-       (name)[_bit_byte(bit)] |= _bit_mask(bit)
+       (name)[_bit_byte(bit)] |= (bitstr_t)_bit_mask(bit)
 
                                /* clear bit N of bitstring name */
 #define        bit_clear(name, bit) \
-       (name)[_bit_byte(bit)] &= ~_bit_mask(bit)
+       (name)[_bit_byte(bit)] &= (bitstr_t)~_bit_mask(bit)
 
                                /* clear bits start ... stop in bitstring */
 #define        bit_nclear(name, start, stop) { \
@@ -81,13 +81,13 @@ typedef     unsigned char bitstr_t;
        register int _startbyte = _bit_byte(_start); \
        register int _stopbyte = _bit_byte(_stop); \
        if (_startbyte == _stopbyte) { \
-               _name[_startbyte] &= ((0xff >> (8 - (_start&0x7))) | \
+               _name[_startbyte] &= (bitstr_t)((0xff >> (8 - (_start&0x7))) | \
                                      (0xff << ((_stop&0x7) + 1))); \
        } else { \
-               _name[_startbyte] &= 0xff >> (8 - (_start&0x7)); \
+               _name[_startbyte] &= (bitstr_t)(0xff >> (8 - (_start&0x7))); \
                while (++_startbyte < _stopbyte) \
                        _name[_startbyte] = 0; \
-               _name[_stopbyte] &= 0xff << ((_stop&0x7) + 1); \
+               _name[_stopbyte] &= (bitstr_t)(0xff << ((_stop&0x7) + 1)); \
        } \
 }
 
@@ -98,13 +98,13 @@ typedef     unsigned char bitstr_t;
        register int _startbyte = _bit_byte(_start); \
        register int _stopbyte = _bit_byte(_stop); \
        if (_startbyte == _stopbyte) { \
-               _name[_startbyte] |= ((0xff << (_start&0x7)) & \
+               _name[_startbyte] |= (bitstr_t)((0xff << (_start&0x7)) & \
                                    (0xff >> (7 - (_stop&0x7)))); \
        } else { \
-               _name[_startbyte] |= 0xff << ((_start)&0x7); \
+               _name[_startbyte] |= (bitstr_t)(0xff << ((_start)&0x7)); \
                while (++_startbyte < _stopbyte) \
                        _name[_startbyte] = 0xff; \
-               _name[_stopbyte] |= 0xff >> (7 - (_stop&0x7)); \
+               _name[_stopbyte] |= (bitstr_t)(0xff >> (7 - (_stop&0x7))); \
        } \
 }
 
index 5e6e2ab72e795e1131ba7a0c18caad34a9f9a117..857d94b4b5012a9dd591bb410717303d42777826 100644 (file)
@@ -308,8 +308,8 @@ int main(int argc, char *argv[]) {
        /* obtain a random scaling factor for RANDOM_DELAY */
        if (gettimeofday(&tv, &tz) != 0)
                tv.tv_usec = 0;
-       srandom(pid + tv.tv_usec);
-       RandomScale = random() / (double)RAND_MAX;
+       srandom((unsigned int)(pid + tv.tv_usec));
+       RandomScale = (double)random() / (double)RAND_MAX;
        snprintf(buf, sizeof(buf), "RANDOM_DELAY will be scaled with factor %d%% if used.", (int)(RandomScale*100));
        log_it("CRON", pid, "INFO", buf, 0);
 
@@ -565,7 +565,7 @@ static void find_jobs(int vtime, cron_db * db, int doWild, int doNonWild, long v
         */
        for (u = db->head; u != NULL; u = u->next) {
                for (e = u->crontab; e != NULL; e = e->next) {
-                       time_t virtualSecond = (vtime - e->delay) * SECONDS_PER_MINUTE;
+                       time_t virtualSecond = (time_t)(vtime - e->delay) * (time_t)SECONDS_PER_MINUTE;
                        time_t virtualGMTSecond = virtualSecond - vGMToff;
                        job_tz = env_get("CRON_TZ", e->envp);
                        maketime(job_tz, orig_tz);
@@ -616,7 +616,7 @@ static void set_time(int initialize) {
                GMToff = get_gmtoff(&StartTime, &tm);
                Debug(DSCH, ("[%ld] GMToff=%ld\n", (long) getpid(), (long) GMToff));
        }
-       clockTime = (StartTime + GMToff) / (time_t) SECONDS_PER_MINUTE;
+       clockTime = (int)((StartTime + GMToff) / (time_t) SECONDS_PER_MINUTE);
 }
 
 /*
index 3659b6e8bc6b6eba903bd3a71e29ad8a97f766d8..8a52e8770a150796c7df812354809c85b1e49855 100644 (file)
@@ -192,7 +192,7 @@ time_t nextmatch(entry *e, time_t start) {
  */
 int matchuser(char *user, char *list) {
        char *pos;
-       int l = strlen(user);
+       size_t l = strlen(user);
 
        for (pos = list; (pos = strstr(pos, user)) != NULL; pos += l) {
                if ((pos != list) && (*(pos - 1) != ','))
index 5916c7806f0e99733e03e06dd0e72cf21263c9b6..811098ba5c3f7134d10fe3a0d52f7c8b6a3d1d9c 100644 (file)
@@ -856,14 +856,14 @@ static int replace_cmd(void) {
        file_owner = (getgid() == geteuid() && getgid() == getegid()) ? ROOT_UID : pw->pw_uid;
 
 #ifdef HAVE_FCHOWN
-       if (fchown(fileno(tmp), file_owner, -1) < OK) {
+       if (fchown(fileno(tmp), file_owner, (gid_t)-1) < OK) {
                perror("fchown");
                fclose(tmp);
                error = -2;
                goto done;
        }
 #else
-       if (chown(TempFilename, file_owner, -1) < OK) {
+       if (chown(TempFilename, file_owner, (gid_t)-1) < OK) {
                perror("chown");
                fclose(tmp);
                error = -2;
index 95c9b66f69b77e42f91d3808ffe120d3a566b9e7..e6cfdf89f730eaf028c5fb8f709ffb9b7fb7af1a 100644 (file)
@@ -353,7 +353,7 @@ void check_inotify_database(cron_db * old_db) {
                new_db.head = new_db.tail = NULL;
                new_db.ifd = old_db->ifd;
                new_db.mtime = time(NULL) - 1;
-               while ((retval = read(old_db->ifd, buf, sizeof (buf))) == -1 &&
+               while ((retval = (int)read(old_db->ifd, buf, sizeof (buf))) == -1 &&
                        errno == EINTR) ;
 
                if (retval == 0) {
@@ -623,7 +623,7 @@ user *find_user(cron_db * db, const char *name, const char *tabname) {
 }
 
 static int not_a_crontab(DIR_T * dp) {
-       int len;
+       size_t len;
 
        /* avoid file names beginning with ".".  this is good
         * because we would otherwise waste two guaranteed calls
@@ -643,10 +643,10 @@ static int not_a_crontab(DIR_T * dp) {
 
        len = strlen(dp->d_name);
 
-       if (len >= NAME_MAX)
-               return (1);     /* XXX log? */
+       if (len >= NAME_MAX || len == 0)
+               return (1);
 
-       if ((len > 0) && (dp->d_name[len - 1] == '~'))
+       if (dp->d_name[len - 1] == '~')
                return (1);
 
        if ((len > 8) && (strncmp(dp->d_name + len - 8, ".rpmsave", 8) == 0))
index 21f16beb627d77f0f77a28cec6e79002b8958e50..9981628b75cfe4c1f2239d8e379fbb83baebf3b9 100644 (file)
@@ -117,7 +117,7 @@ static int child_process(entry * e, char **jobenv) {
                char *pch;
 
                for (pch = ProgramName; *pch; pch++)
-                       *pch = MkUpper(*pch);
+                       *pch = (char)MkUpper(*pch);
        }
 #endif /* CAPITALIZE_FOR_PS */
 
@@ -156,10 +156,10 @@ static int child_process(entry * e, char **jobenv) {
                for (input_data = p = e->cmd;
                        (ch = *input_data) != '\0'; input_data++, p++) {
                        if (p != input_data)
-                               *p = ch;
+                               *p = (char)ch;
                        if (escaped) {
                                if (ch == '%')
-                                       *--p = ch;
+                                       *--p = (char)ch;
                                escaped = FALSE;
                                continue;
                        }
@@ -376,7 +376,7 @@ static int child_process(entry * e, char **jobenv) {
                        int bufidx = 0;
                        if (SyslogOutput) {
                                if (ch != '\n')
-                                       logbuf[bufidx++] = ch;
+                                       logbuf[bufidx++] = (char)ch;
                        }
 #endif
 
@@ -505,7 +505,7 @@ static int child_process(entry * e, char **jobenv) {
                                        putc(ch, mail);
 #if defined(SYSLOG)
                                if (SyslogOutput) {
-                                       logbuf[bufidx++] = ch;
+                                       logbuf[bufidx++] = (char)ch;
                                        if ((ch == '\n') || (bufidx == sizeof(logbuf)-1)) {
                                                if (ch == '\n')
                                                        logbuf[bufidx-1] = '\0';
index 1eb1e1d66a9ce30a60bd129aab876efc0a2ed9a1..92b55f5290abe4f99fc1f4e8e5238bd8604a0975 100644 (file)
@@ -314,7 +314,7 @@ entry *load_entry(FILE * file, void (*error_func) (), struct passwd *pw,
                if (errno != 0 || val < 0 || val > 24*60) {
                        log_it("CRON", getpid(), "ERROR", "bad value of RANDOM_DELAY", 0);
                } else {
-                       e->delay = val * RandomScale;
+                       e->delay = (int)((double)val * RandomScale);
                }
        }
 
@@ -568,7 +568,7 @@ get_number(int *numptr, int low, const char *names[], int ch, FILE * file,
        while (isdigit((unsigned char) ch)) {
                if (++len >= MAX_TEMPSTR)
                        goto bad;
-               *pc++ = ch;
+               *pc++ = (char)ch;
                ch = get_char(file);
        }
        *pc = '\0';
@@ -585,7 +585,7 @@ get_number(int *numptr, int low, const char *names[], int ch, FILE * file,
                while (isalpha((unsigned char) ch)) {
                        if (++len >= MAX_TEMPSTR)
                                goto bad;
-                       *pc++ = ch;
+                       *pc++ = (char)ch;
                        ch = get_char(file);
                }
                *pc = '\0';
index 4a9051a19b86858f2ed5a77a45cb7f6110b75e1e..6cf09003304a3fbfc6734e63abcc95b2457e5c86 100644 (file)
--- a/src/env.c
+++ b/src/env.c
@@ -52,7 +52,8 @@ void env_free(char **envp) {
 }
 
 char **env_copy(char **envp) {
-       int count, i, save_errno;
+       int save_errno;
+       size_t count, i;
        char **p;
 
        for (count = 0; envp[count] != NULL; count++) ;
@@ -74,21 +75,21 @@ char **env_copy(char **envp) {
 }
 
 char **env_set(char **envp, const char *envstr) {
-       int count, found;
+       size_t count, found;
        char **p, *envtmp;
 
        /*
         * count the number of elements, including the null pointer;
         * also set 'found' to -1 or index of entry if already in here.
         */
-       found = -1;
+       found = (size_t)-1;
        for (count = 0; envp[count] != NULL; count++) {
                if (!strcmp_until(envp[count], envstr, '='))
                        found = count;
        }
        count++;        /* for the NULL */
 
-       if (found != -1) {
+       if (found != (size_t)-1) {
                /*
                 * it exists already, so just free the existing setting,
                 * save our new one there, and return the existing array.
@@ -108,7 +109,7 @@ char **env_set(char **envp, const char *envstr) {
        if ((envtmp = strdup(envstr)) == NULL)
                return (NULL);
        p = (char **) realloc((void *) envp,
-               (size_t) ((count + 1) * sizeof (char *)));
+               (count + 1) * sizeof (char *));
        if (p == NULL) {
                free(envtmp);
                return (NULL);
@@ -286,7 +287,7 @@ int load_env(char *envstr, FILE * f) {
 }
 
 char *env_get(const char *name, char **envp) {
-       int len = strlen(name);
+       size_t len = strlen(name);
        char *p, *q;
 
        while ((p = *envp++) != NULL) {
index ee50821c3a47383a010f0ab8f51c037835bd4d7c..d2b8965d35bc65871c34bb4dbc33e9af02be99c9 100644 (file)
@@ -71,14 +71,14 @@ int         load_database(cron_db *),
                cron_pclose(FILE *),
                glue_strings(char *, size_t, const char *, const char *, char),
                strcmp_until(const char *, const char *, char),
-               allowed(const char * ,const char * ,const char *),
-               strdtb(char *);
+               allowed(const char * ,const char * ,const char *);
 
-size_t         strlens(const char *, ...);
+size_t         strlens(const char *, ...),
+               strdtb(char *);
 
 char           *env_get(const char *, char **),
                *arpadate(time_t *),
-               *mkprints(unsigned char *, unsigned int),
+               *mkprints(unsigned char *, size_t),
                *first_word(const char *, const char *),
                **env_init(void),
                **env_copy(char **),
index 4b9d20ff441a1b04d0618847bc398915b5e9d03d..4efab641050c412a0fc3d0e4bcaccbe2b07d81ea 100644 (file)
@@ -143,7 +143,7 @@ int strcmp_until(const char *left, const char *right, char until) {
 
 /* strdtb(s) - delete trailing blanks in string 's' and return new length
  */
-int strdtb(char *s) {
+size_t strdtb(char *s) {
        char *x = s;
 
        /* scan forward to the null
@@ -166,7 +166,7 @@ int strdtb(char *s) {
        /* the difference between the position of the null character and
         * the position of the first character of the string is the length.
         */
-       return (x - s);
+       return ((size_t)(x - s));
 }
 
 int set_debug_flags(const char *flags) {
@@ -362,8 +362,8 @@ void acquire_daemonlock(int closeflag) {
 
        sprintf(buf, "%ld\n", (long) pid);
        (void) lseek(fd, (off_t) 0, SEEK_SET);
-       len = strlen(buf);
-       if ((num = write(fd, buf, len)) != len)
+       len = (ssize_t)strlen(buf);
+       if ((num = write(fd, buf, (size_t)len)) != len)
                log_it("CRON", pid, "ERROR", "write() failed", errno);
        else {
                if (ftruncate(fd, num) == -1)
@@ -651,7 +651,7 @@ char *first_word(const char *s, const char *t) {
 /* warning:
  *     heavily ascii-dependent.
  */
-static void mkprint(char *dst, unsigned char *src, int len) {
+static void mkprint(char *dst, unsigned char *src, size_t len) {
 /*
  * XXX
  * We know this routine can't overflow the dst buffer because mkprints()
@@ -662,10 +662,10 @@ static void mkprint(char *dst, unsigned char *src, int len) {
 
                if (ch < ' ') { /* control character */
                        *dst++ = '^';
-                       *dst++ = ch + '@';
+                       *dst++ = (char)(ch + '@');
                }
                else if (ch < 0177) {   /* printable */
-                       *dst++ = ch;
+                       *dst++ = (char)ch;
                }
                else if (ch == 0177) {  /* delete/rubout */
                        *dst++ = '^';
@@ -682,7 +682,7 @@ static void mkprint(char *dst, unsigned char *src, int len) {
 /* warning:
  *     returns a pointer to malloc'd storage, you must call free yourself.
  */
-char *mkprints(unsigned char *src, unsigned int len) {
+char *mkprints(unsigned char *src, size_t len) {
        char *dst = malloc(len * 4 + 1);
 
        if (dst)
index f9478fe38b3c2513e2b480bf82096a897b741650..eaea20a54bd3b11fe5934d6bec86a49bc9a0d4f9 100644 (file)
@@ -81,9 +81,9 @@ FILE *cron_popen(char *program, const char *type, struct passwd *pw, char **jobe
        if (!pids) {
                if ((fds = getdtablesize()) <= 0)
                        return (NULL);
-               if (!(pids = (PID_T *) malloc((u_int) (fds * sizeof (PID_T)))))
+               if (!(pids = (PID_T *) malloc((u_int) ((size_t)fds * sizeof (PID_T)))))
                        return (NULL);
-               memset((char *) pids, 0, fds * sizeof (PID_T));
+               memset((char *) pids, 0, (size_t)fds * sizeof (PID_T));
        }
        if (pipe(pdes) < 0)
                return (NULL);