summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>2012-05-29 11:34:38 +0000
committerjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>2012-05-29 11:34:38 +0000
commitc306fbbf0ceba0231ccfd134fb69341ec482c09c (patch)
treec2b60359132356dcde0e153b19936cc26691c1d9
parent8cf857d4ccdc826115980899588b656b05886092 (diff)
downloadgcc-c306fbbf0ceba0231ccfd134fb69341ec482c09c.tar.gz
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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@187952 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--gcc/ChangeLog9
-rw-r--r--gcc/gcov.c11
-rw-r--r--gcc/input.c13
3 files changed, 14 insertions, 19 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 513405ff202..19048dbcccc 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -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):
diff --git a/gcc/gcov.c b/gcc/gcov.c
index 97071115be5..d4823991d14 100644
--- a/gcc/gcov.c
+++ b/gcc/gcov.c
@@ -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;
diff --git a/gcc/input.c b/gcc/input.c
index 5f14489753f..ece72826224 100644
--- a/gcc/input.c
+++ b/gcc/input.c
@@ -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;