]> sourceware.org Git - glibc.git/commitdiff
(__argp_fmtstream_ensure): Check for size_t overflow when reallocating storage.
authorUlrich Drepper <drepper@redhat.com>
Thu, 25 Sep 2003 05:34:28 +0000 (05:34 +0000)
committerUlrich Drepper <drepper@redhat.com>
Thu, 25 Sep 2003 05:34:28 +0000 (05:34 +0000)
argp/argp-fmtstream.c

index d06ea8453bc1df2c163c2cebb9b857af98f8d354..215160bdcd430c6fdaeedc698eb22ffc7d76d665 100644 (file)
@@ -385,10 +385,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;
This page took 0.043011 seconds and 5 git commands to generate.