Skip to content

Commit 1f59dd8

Browse files
author
Daniel Kroening
authored
Merge pull request #2955 from chrisr-diffblue/cleanup-error-handling-elf_reader
Cleanup error handling elf reader
2 parents 3dfbac7 + f17ae97 commit 1f59dd8

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

src/goto-programs/elf_reader.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Module: Read ELF
1010
/// Read ELF
1111

1212
#include "elf_reader.h"
13+
#include <util/exception_utils.h>
1314

1415
#include <istream>
1516

@@ -21,13 +22,13 @@ elf_readert::elf_readert(std::istream &_in):in(_in)
2122
sizeof(elf32_header));
2223

2324
if(!in)
24-
throw "failed to read ELF header";
25+
throw deserialization_exceptiont("failed to read ELF header");
2526

2627
if(elf32_header.e_ident[0]!=0x7f ||
2728
elf32_header.e_ident[1]!='E' ||
2829
elf32_header.e_ident[2]!='L' ||
2930
elf32_header.e_ident[3]!='F')
30-
throw "ELF header malformed (magic)"; // NOLINT(readability/throw)
31+
throw deserialization_exceptiont("ELF header malformed (magic)");
3132

3233
elf_class=(elf_classt)elf32_header.e_ident[4];
3334

@@ -40,15 +41,15 @@ elf_readert::elf_readert(std::istream &_in):in(_in)
4041
else if(ei_data==2)
4142
little_endian=false;
4243
else
43-
throw "ELF32 header malformed (EI_DATA)"; // NOLINT(readability/throw)
44+
throw deserialization_exceptiont("ELF32 header malformed (EI_DATA)");
4445

4546
if(elf32_header.e_version!=1)
46-
throw "unknown ELF32 version";
47+
throw deserialization_exceptiont("unknown ELF32 version");
4748

4849
// get offset for section header
4950
if(elf32_header.e_shoff==0 ||
5051
elf32_header.e_shnum==0)
51-
throw "ELF32 without section header"; // NOLINT(readability/throw)
52+
throw deserialization_exceptiont("ELF32 without section header");
5253

5354
elf32_section_header_table.resize(elf32_header.e_shnum);
5455
number_of_sections=elf32_header.e_shnum;
@@ -68,7 +69,7 @@ elf_readert::elf_readert(std::istream &_in):in(_in)
6869
// string table
6970
unsigned string_table_nr=elf32_header.e_shstrndx;
7071
if(string_table_nr>=elf32_section_header_table.size())
71-
throw "ELF32 without string table"; // NOLINT(readability/throw)
72+
throw deserialization_exceptiont("ELF32 without string table");
7273

7374
string_table_offset=section_offset(string_table_nr);
7475
}
@@ -87,15 +88,15 @@ elf_readert::elf_readert(std::istream &_in):in(_in)
8788
else if(ei_data==2)
8889
little_endian=false;
8990
else
90-
throw "ELF64 header malformed (EI_DATA)"; // NOLINT(readability/throw)
91+
throw deserialization_exceptiont("ELF64 header malformed (EI_DATA)");
9192

9293
if(elf64_header.e_version!=1)
93-
throw "unknown ELF64 version";
94+
throw deserialization_exceptiont("unknown ELF64 version");
9495

9596
// get offset for section header
9697
if(elf64_header.e_shoff==0 ||
9798
elf64_header.e_shnum==0)
98-
throw "ELF64 without section header"; // NOLINT(readability/throw)
99+
throw deserialization_exceptiont("ELF64 without section header");
99100

100101
elf64_section_header_table.resize(elf64_header.e_shnum);
101102
number_of_sections=elf64_header.e_shnum;
@@ -115,7 +116,7 @@ elf_readert::elf_readert(std::istream &_in):in(_in)
115116
// string table
116117
unsigned string_table_nr=elf64_header.e_shstrndx;
117118
if(string_table_nr>=elf64_section_header_table.size())
118-
throw "ELF64 without string table"; // NOLINT(readability/throw)
119+
throw deserialization_exceptiont("ELF64 without string table");
119120

120121
string_table_offset=section_offset(string_table_nr);
121122
}

0 commit comments

Comments
 (0)