mirror of
git://git.sv.gnu.org/coreutils.git
synced 2026-07-28 03:19:55 +02:00
basenc: allocate buffers on heap
Allocate the encoding/decoding buffers dynamically on the heap instead of using variable-length-array (VLA) on the stack. Discussed in https://lists.gnu.org/r/coreutils/2019-01/msg00004.html . * src/basenc.c (do_encode,do_decode): Allocate inbuf/outbuf using xmalloc, and free if using LINT.
This commit is contained in:
+13
-4
@@ -976,10 +976,12 @@ static void
|
||||
do_encode (FILE *in, FILE *out, uintmax_t wrap_column)
|
||||
{
|
||||
size_t current_column = 0;
|
||||
char inbuf[ENC_BLOCKSIZE];
|
||||
char outbuf[BASE_LENGTH (ENC_BLOCKSIZE)];
|
||||
char *inbuf, *outbuf;
|
||||
size_t sum;
|
||||
|
||||
inbuf = xmalloc (ENC_BLOCKSIZE);
|
||||
outbuf = xmalloc (BASE_LENGTH (ENC_BLOCKSIZE));
|
||||
|
||||
do
|
||||
{
|
||||
size_t n;
|
||||
@@ -1010,16 +1012,21 @@ do_encode (FILE *in, FILE *out, uintmax_t wrap_column)
|
||||
|
||||
if (ferror (in))
|
||||
die (EXIT_FAILURE, errno, _("read error"));
|
||||
|
||||
IF_LINT (free (inbuf));
|
||||
IF_LINT (free (outbuf));
|
||||
}
|
||||
|
||||
static void
|
||||
do_decode (FILE *in, FILE *out, bool ignore_garbage)
|
||||
{
|
||||
char inbuf[BASE_LENGTH (DEC_BLOCKSIZE)];
|
||||
char outbuf[DEC_BLOCKSIZE];
|
||||
char *inbuf, *outbuf;
|
||||
size_t sum;
|
||||
struct base_decode_context ctx;
|
||||
|
||||
inbuf = xmalloc (BASE_LENGTH (DEC_BLOCKSIZE));
|
||||
outbuf = xmalloc (DEC_BLOCKSIZE);
|
||||
|
||||
#if BASE_TYPE == 42
|
||||
ctx.inbuf = NULL;
|
||||
#endif
|
||||
@@ -1077,6 +1084,8 @@ do_decode (FILE *in, FILE *out, bool ignore_garbage)
|
||||
#if BASE_TYPE == 42
|
||||
IF_LINT (free (ctx.inbuf));
|
||||
#endif
|
||||
IF_LINT (free (inbuf));
|
||||
IF_LINT (free (outbuf));
|
||||
}
|
||||
|
||||
int
|
||||
|
||||
Reference in New Issue
Block a user