diff options
author | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2020-02-14 04:27:50 +0000 |
---|---|---|
committer | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2020-02-14 04:27:50 +0000 |
commit | 99a1345ecefc62f1ff2d0ccfe41c90abc657995c (patch) | |
tree | d451bbc57081b65a08a10b5c26f75c2927b0e440 /lib | |
parent | 278e20580cc2a30ee5b055192868617bb0d102de (diff) | |
download | netpbm-mirror-99a1345ecefc62f1ff2d0ccfe41c90abc657995c.tar.gz netpbm-mirror-99a1345ecefc62f1ff2d0ccfe41c90abc657995c.tar.xz netpbm-mirror-99a1345ecefc62f1ff2d0ccfe41c90abc657995c.zip |
Release 10.86.09
git-svn-id: http://svn.code.sf.net/p/netpbm/code/stable@3737 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pmfileio.c | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/lib/pmfileio.c b/lib/pmfileio.c index 33f89110..bea01abe 100644 --- a/lib/pmfileio.c +++ b/lib/pmfileio.c @@ -815,6 +815,10 @@ pm_read_unknown_size(FILE * const file, nalloc = PM_BUF_SIZE; MALLOCARRAY(buf, nalloc); + if (!buf) + pm_error("Failed to allocate %lu bytes for read buffer", + (unsigned long) nalloc); + eof = FALSE; /* initial value */ while(!eof) { @@ -825,7 +829,10 @@ pm_read_unknown_size(FILE * const file, nalloc += PM_MAX_BUF_INC; else nalloc += nalloc; - REALLOCARRAY_NOFAIL(buf, nalloc); + REALLOCARRAY(buf, nalloc); + if (!buf) + pm_error("Failed to allocate %lu bytes for read buffer", + (unsigned long) nalloc); } val = getc(file); @@ -889,14 +896,27 @@ pm_getline(FILE * const ifP, /* + 2 = 1 for 'c', one for terminating NUL */ bufferSz += 128; REALLOCARRAY(buffer, bufferSz); + if (!buffer) { + pm_error("Failed to allocate %lu bytes for buffer " + "to assemble a line of input", + (unsigned long) bufferSz); + } } buffer[nReadSoFar++] = c; } } } - if (gotLine) + if (gotLine) { + bufferSz = nReadSoFar + 1; + REALLOCARRAY(buffer, bufferSz); + if (!buffer) { + pm_error("Failed to allocate %lu bytes for buffer " + "to assemble a line of input", + (unsigned long) bufferSz); + } buffer[nReadSoFar] = '\0'; + } *eofP = eof; *bufferP = buffer; |