re PR middle-end/53510 (OOM while compile some code)
authorJakub Jelinek <jakub@redhat.com>
Tue, 29 May 2012 11:34:38 +0000 (13:34 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Tue, 29 May 2012 11:34:38 +0000 (13:34 +0200)
PR middle-end/53510
* input.c (read_line): Use XRESIZEVEC instead of XNEWVEC
to avoid leaking memory.  No need to handle memory allocation
failure.  Double string_len on each reallocation instead of
adding 2.
* gcov.c (read_line): Likewise.

From-SVN: r187952

gcc/ChangeLog
gcc/gcov.c
gcc/input.c

index 513405ff202a60808f850bbc21df6b876f7bb44e..19048dbcccc36fb6b4029c07489d944ddd37d1c2 100644 (file)
@@ -1,3 +1,12 @@
+2012-05-29  Jakub Jelinek  <jakub@redhat.com>
+
+       PR middle-end/53510
+       * input.c (read_line): Use XRESIZEVEC instead of XNEWVEC
+       to avoid leaking memory.  No need to handle memory allocation
+       failure.  Double string_len on each reallocation instead of
+       adding 2.
+       * gcov.c (read_line): Likewise.
+
 2012-05-29  Hans-Peter Nilsson  <hp@axis.com>
 
        * config/cris/cris.h (TARGET_HAS_BREAK, TARGET_TRAP_USING_BREAK8):
index 97071115be5e606dccaecf9d0f65f19324404f8c..d4823991d14e7ef4c91ad9c3e2359e6ebf54bce0 100644 (file)
@@ -2219,15 +2219,8 @@ read_line (FILE *file)
          return string;
        }
       pos += len;
-      ptr = XNEWVEC (char, string_len * 2);
-      if (ptr)
-       {
-         memcpy (ptr, string, pos);
-         string = ptr;
-         string_len += 2;
-       }
-      else
-       pos = 0;
+      string = XRESIZEVEC (char, string, string_len * 2);
+      string_len *= 2;
     }
       
   return pos ? string : NULL;
index 5f14489753f20d408f1cf133e1a6be3e03808c1d..ece7282622464a113a5dbd5fea59d360c8afb4f4 100644 (file)
@@ -1,5 +1,5 @@
 /* Data and functions related to line maps and input files.
-   Copyright (C) 2004, 2007, 2008, 2009, 2010, 2011
+   Copyright (C) 2004, 2007, 2008, 2009, 2010, 2011, 2012
    Free Software Foundation, Inc.
 
 This file is part of GCC.
@@ -105,15 +105,8 @@ read_line (FILE *file)
          return string;
        }
       pos += len;
-      ptr = XNEWVEC (char, string_len * 2);
-      if (ptr)
-       {
-         memcpy (ptr, string, pos);
-         string = ptr;
-         string_len += 2;
-       }
-      else
-       pos = 0;
+      string = XRESIZEVEC (char, string, string_len * 2);
+      string_len *= 2;
     }
       
   return pos ? string : NULL;