]> granicus.if.org Git - flex/commitdiff
add (size_t) casts to malloc invocations to prevent warnings
authorrlar <rlar>
Mon, 29 Feb 2016 19:15:29 +0000 (20:15 +0100)
committerWill Estes <westes575@gmail.com>
Tue, 1 Mar 2016 11:05:21 +0000 (06:05 -0500)
src/filter.c
src/misc.c
src/scanopt.c
src/tables.c

index c58406df310d9c4775b8a8f36d5ec13a8a5eebab..9500f965a1bbfa669e8282abcbf6f93e2f8b4d7e 100644 (file)
@@ -66,7 +66,7 @@ struct filter *filter_create_ext (struct filter *chain, const char *cmd,
 
        /* allocate argv, and populate it with the argument list. */
        max_args = 8;
-       f->argv = malloc(sizeof(char *) * (max_args + 1));
+       f->argv = malloc(sizeof(char *) * (size_t) (max_args + 1));
        if (!f->argv)
                flexerror(_("malloc failed (f->argv) in filter_create_ext"));
        f->argv[f->argc++] = cmd;
@@ -75,7 +75,7 @@ struct filter *filter_create_ext (struct filter *chain, const char *cmd,
        while ((s = va_arg (ap, const char *)) != NULL) {
                if (f->argc >= max_args) {
                        max_args += 8;
-                       f->argv = realloc(f->argv, sizeof(char*) * (max_args + 1));
+                       f->argv = realloc(f->argv, sizeof(char*) * (size_t) (max_args + 1));
                }
                f->argv[f->argc++] = s;
        }
@@ -283,7 +283,7 @@ int filter_tee_header (struct filter *chain)
        fprintf (to_c, "m4_define( [[M4_YY_OUTFILE_NAME]],[[%s]])m4_dnl\n",
                 outfilename ? outfilename : "<stdout>");
 
-       buf = malloc(readsz);
+       buf = malloc((size_t) readsz);
        if (!buf)
                flexerror(_("malloc failed in filter_tee_header"));
        while (fgets (buf, readsz, stdin)) {
index 0d93e4bb91f7de06ae97719cdba369081a72a59e..a2f67fc3287f2d6a04a3e4cc13caf7868c5d2e4d 100644 (file)
@@ -60,7 +60,7 @@ static void sko_push(bool dc)
 {
     if(!sko_stack){
         sko_sz = 1;
-        sko_stack = malloc(sizeof(struct sko_state) * sko_sz);
+        sko_stack = malloc(sizeof(struct sko_state) * (size_t) sko_sz);
         if (!sko_stack)
             flexfatal(_("allocation of sko_stack failed"));
         sko_len = 0;
@@ -68,7 +68,7 @@ static void sko_push(bool dc)
     if(sko_len >= sko_sz){
         sko_sz *= 2;
         sko_stack = realloc(sko_stack,
-                       sizeof(struct sko_state) * sko_sz);
+                       sizeof(struct sko_state) * (size_t) sko_sz);
     }
     
     /* initialize to zero and push */
@@ -883,7 +883,7 @@ void   *yy_flex_xmalloc (int size)
 {
        void   *result;
 
-       result = malloc(size);
+       result = malloc((size_t) size);
        if (!result)
                flexfatal (_
                           ("memory allocation failed in yy_flex_xmalloc()"));
index d829d0ff7331e4f63210f075a74593cbc54e979d..a11854168fa8947e35115e3a80b54a687a0ca670 100644 (file)
@@ -157,7 +157,7 @@ scanopt_t *scanopt_init (const optspec_t *options, int argc, char **argv, int fl
                s->optc++;
 
        /* Build auxiliary data */
-       s->aux = malloc(s->optc * sizeof (struct _aux));
+       s->aux = malloc((size_t) s->optc * sizeof (struct _aux));
 
        for (i = 0; i < s->optc; i++) {
                const unsigned char *p, *pname;
@@ -261,7 +261,7 @@ int     scanopt_usage (scanopt_t *scanner, FILE *fp, const char *usage)
        fprintf (fp, "\n");
 
        /* Sort by r_val and string. Yes, this is O(n*n), but n is small. */
-       store = malloc(s->optc * sizeof (usg_elem));
+       store = malloc((size_t) s->optc * sizeof (usg_elem));
        for (i = 0; i < s->optc; i++) {
 
                /* grab the next preallocate node. */
index ff89b4d87fdb527eb967c1afd0feb97e6f5efc71..3d043c681d2444600e8f635f5d21e529111a7476 100644 (file)
@@ -481,7 +481,7 @@ void yytbl_data_compress (struct yytbl_data *tbl)
        }
 
        total_len = yytbl_calc_total_len (tbl);
-       newtbl.td_data = calloc (total_len, newsz);
+       newtbl.td_data = calloc ((size_t) total_len, newsz);
        newtbl.td_flags =
                TFLAGS_CLRDATA (newtbl.td_flags) | BYTES2TFLAG (newsz);