X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Fargp-fmtstream.c;h=c88c3db2147136dbb8931f0b50dc1953b050b940;hb=1caf9135115db922238f1a9e9e52759e251454a3;hp=c6d79a56fcacdb14e3df67ae4ea996622f177576;hpb=a82fdff58064e24994117ed668ae13362253be46;p=gnulib.git diff --git a/lib/argp-fmtstream.c b/lib/argp-fmtstream.c index c6d79a56f..c88c3db21 100644 --- a/lib/argp-fmtstream.c +++ b/lib/argp-fmtstream.c @@ -384,10 +384,11 @@ __argp_fmtstream_ensure (struct argp_fmtstream *fs, size_t amount) if ((size_t) (fs->end - fs->buf) < amount) /* Gotta grow the buffer. */ { - size_t new_size = fs->end - fs->buf + amount; - char *new_buf = realloc (fs->buf, new_size); + size_t old_size = fs->end - fs->buf; + size_t new_size = old_size + amount; + char *new_buf; - if (! new_buf) + if (new_size < old_size || ! (new_buf = realloc (fs->buf, new_size))) { __set_errno (ENOMEM); return 0;