Skip to content

Commit

Permalink
Avoid the use of variable length arrays.
Browse files Browse the repository at this point in the history
Microsoft has not implemented and refuses to implement C99 aspects
that are not also part of C++11 or later C++ standards. (Note that
the "99" in C99 refers to 1999. That was the year my younger son
was born, who is now applying for college.)
  • Loading branch information
madler committed Oct 12, 2016
1 parent 4079828 commit bc280f8
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions pigz.c
Expand Up @@ -1003,8 +1003,9 @@ local unsigned put(int out, ...) {
}
va_end(ap);

/* allocate memory on the stack for the data */
unsigned char wrap[count], *next = wrap;
/* allocate memory for the data */
unsigned char *wrap = alloc(NULL, count);
unsigned char *next = wrap;

/* write the requested data to wrap[] */
va_start(ap, out);
Expand All @@ -1017,17 +1018,18 @@ local unsigned put(int out, ...) {
*next++ = val >> n;
} while (n);
}
else { /* little endian */
else /* little endian */
do {
*next++ = val;
val >>= 8;
} while (--n);
}
}
va_end(ap);

/* write wrap[] to out and return the number of bytes written */
return writen(out, wrap, count);
writen(out, wrap, count);
free(wrap);
return count;
}

/* Low 32-bits set to all ones. */
Expand Down

0 comments on commit bc280f8

Please sign in to comment.