From: Mark Wielaard Date: Mon, 8 Jun 2015 22:31:25 +0000 (+0200) Subject: libdw: Initialize dirarray early in read_srclines. X-Git-Tag: elfutils-0.162~4 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=9e3d5c2656c993e391cc126f9e1bb921e0af4873;p=thirdparty%2Felfutils.git libdw: Initialize dirarray early in read_srclines. 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 --- diff --git a/libdw/ChangeLog b/libdw/ChangeLog index e9b81f6d6..487e34a70 100644 --- a/libdw/ChangeLog +++ b/libdw/ChangeLog @@ -1,3 +1,7 @@ +2015-06-08 Mark Wielaard + + * dwarf_getsrclines.c (read_srclines): Initialize dirarray early. + 2015-06-06 Mark Wielaard * dwarf_getsrclines.c (read_srclines): Initialize filelist early. diff --git a/libdw/dwarf_getsrclines.c b/libdw/dwarf_getsrclines.c index ba9649a69..389c824de 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))