[PATCH] libdw: Initialize dirarray early in read_srclines.
Mark Wielaard
mjw at redhat.com
Mon Jun 8 22:34:37 UTC 2015
We might jump to "out" early on error. Help gcc see that isn't an issue
by initializing dirarray to dirstack early.
Signed-off-by: Mark Wielaard <mjw at redhat.com>
---
libdw/ChangeLog | 4 ++++
libdw/dwarf_getsrclines.c | 20 ++++++++++----------
2 files changed, 14 insertions(+), 10 deletions(-)
diff --git a/libdw/ChangeLog b/libdw/ChangeLog
index e9b81f6..487e34a 100644
--- a/libdw/ChangeLog
+++ b/libdw/ChangeLog
@@ -1,3 +1,7 @@
+2015-06-08 Mark Wielaard <mjw at redhat.com>
+
+ * dwarf_getsrclines.c (read_srclines): Initialize dirarray early.
+
2015-06-06 Mark Wielaard <mjw at redhat.com>
* dwarf_getsrclines.c (read_srclines): Initialize filelist early.
diff --git a/libdw/dwarf_getsrclines.c b/libdw/dwarf_getsrclines.c
index ba9649a..389c824 100644
--- a/libdw/dwarf_getsrclines.c
+++ b/libdw/dwarf_getsrclines.c
@@ -111,6 +111,14 @@ read_srclines (Dwarf *dbg,
#define MAX_STACK_FILES (MAX_STACK_ALLOC / 4)
#define MAX_STACK_DIRS (MAX_STACK_ALLOC / 16)
+ struct dirlist
+ {
+ const char *dir;
+ size_t len;
+ };
+ struct dirlist dirstack[MAX_STACK_DIRS];
+ struct dirlist *dirarray = dirstack;
+
if (unlikely (linep + 4 > lineendp))
{
invalid_data:
@@ -186,11 +194,7 @@ read_srclines (Dwarf *dbg,
/* First comes the list of directories. Add the compilation
directory first since the index zero is used for it. */
- struct dirlist
- {
- const char *dir;
- size_t len;
- } comp_dir_elem =
+ struct dirlist comp_dir_elem =
{
.dir = comp_dir,
.len = comp_dir ? strlen (comp_dir) : 0,
@@ -209,11 +213,7 @@ read_srclines (Dwarf *dbg,
}
/* Arrange the list in array form. */
- struct dirlist dirstack[MAX_STACK_DIRS];
- struct dirlist *dirarray;
- if (ndirlist < MAX_STACK_DIRS)
- dirarray = dirstack;
- else
+ if (ndirlist >= MAX_STACK_DIRS)
{
dirarray = (struct dirlist *) malloc (ndirlist * sizeof (*dirarray));
if (unlikely (dirarray == NULL))
--
2.1.0
More information about the elfutils-devel
mailing list