This is the mail archive of the binutils-cvs@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[binutils-gdb] Replace reachable assertion with a test and return of NULL.


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=68807c3cd64ccc4f0e9261df3e840d30d9a19b51

commit 68807c3cd64ccc4f0e9261df3e840d30d9a19b51
Author: Nick Clifton <nickc@redhat.com>
Date:   Tue Feb 6 16:05:13 2018 +0000

    Replace reachable assertion with a test and return of NULL.
    
    	PR 22793
    	* readelf.c (find_section): Replace assertion with test and return
    	of NULL.
    	(find_section_by_address): Add test of section header table
    	existance.
    	(find_section_by_type): Likewise.
    	(find_section_in_set): Likewise.

Diff:
---
 binutils/ChangeLog | 10 ++++++++++
 binutils/readelf.c | 12 +++++++++++-
 2 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/binutils/ChangeLog b/binutils/ChangeLog
index f6f3e99..1e7e581 100644
--- a/binutils/ChangeLog
+++ b/binutils/ChangeLog
@@ -1,3 +1,13 @@
+2018-02-06  Nick Clifton  <nickc@redhat.com>
+
+	PR 22793
+	* readelf.c (find_section): Replace assertion with test and return
+	of NULL.
+	(find_section_by_address): Add test of section header table
+	existance.
+	(find_section_by_type): Likewise.
+	(find_section_in_set): Likewise.
+
 2018-02-05  Maciej W. Rozycki  <macro@mips.com>
 
 	* testsuite/binutils-all/mips/mips-reginfo.d: New test.
diff --git a/binutils/readelf.c b/binutils/readelf.c
index ae1cda9..e3af50a 100644
--- a/binutils/readelf.c
+++ b/binutils/readelf.c
@@ -655,7 +655,8 @@ find_section (Filedata * filedata, const char * name)
 {
   unsigned int i;
 
-  assert (filedata->section_headers != NULL);
+  if (filedata->section_headers == NULL)
+    return NULL;
 
   for (i = 0; i < filedata->file_header.e_shnum; i++)
     if (streq (SECTION_NAME (filedata->section_headers + i), name))
@@ -672,6 +673,9 @@ find_section_by_address (Filedata * filedata, bfd_vma addr)
 {
   unsigned int i;
 
+  if (filedata->section_headers == NULL)
+    return NULL;
+
   for (i = 0; i < filedata->file_header.e_shnum; i++)
     {
       Elf_Internal_Shdr *sec = filedata->section_headers + i;
@@ -688,6 +692,9 @@ find_section_by_type (Filedata * filedata, unsigned int type)
 {
   unsigned int i;
 
+  if (filedata->section_headers == NULL)
+    return NULL;
+
   for (i = 0; i < filedata->file_header.e_shnum; i++)
     {
       Elf_Internal_Shdr *sec = filedata->section_headers + i;
@@ -707,6 +714,9 @@ find_section_in_set (Filedata * filedata, const char * name, unsigned int * set)
 {
   unsigned int i;
 
+  if (filedata->section_headers == NULL)
+    return NULL;
+
   if (set != NULL)
     {
       while ((i = *set++) > 0)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]