Skip to content

Commit ef6f236

Browse files
tautschnigjparsert
authored andcommitted
Cleanup read_bin_goto_object
Remove unnecessary braces that obscure control flow, and remove commented-out code that has no use.
1 parent adf4d20 commit ef6f236

File tree

1 file changed

+43
-50
lines changed

1 file changed

+43
-50
lines changed

src/goto-programs/read_bin_goto_object.cpp

Lines changed: 43 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -214,70 +214,63 @@ bool read_bin_goto_object(
214214
{
215215
messaget message(message_handler);
216216

217-
{
218-
char hdr[4];
219-
hdr[0]=static_cast<char>(in.get());
220-
hdr[1]=static_cast<char>(in.get());
221-
hdr[2]=static_cast<char>(in.get());
217+
char hdr[4];
218+
hdr[0] = static_cast<char>(in.get());
219+
hdr[1] = static_cast<char>(in.get());
220+
hdr[2] = static_cast<char>(in.get());
222221

223-
if(hdr[0]=='G' && hdr[1]=='B' && hdr[2]=='F')
222+
if(hdr[0] == 'G' && hdr[1] == 'B' && hdr[2] == 'F')
223+
{
224+
// OK!
225+
}
226+
else
227+
{
228+
hdr[3] = static_cast<char>(in.get());
229+
if(hdr[0] == 0x7f && hdr[1] == 'G' && hdr[2] == 'B' && hdr[3] == 'F')
224230
{
225231
// OK!
226232
}
227-
else
233+
else if(hdr[0] == 0x7f && hdr[1] == 'E' && hdr[2] == 'L' && hdr[3] == 'F')
228234
{
229-
hdr[3]=static_cast<char>(in.get());
230-
if(hdr[0]==0x7f && hdr[1]=='G' && hdr[2]=='B' && hdr[3]=='F')
231-
{
232-
// OK!
233-
}
234-
else if(hdr[0]==0x7f && hdr[1]=='E' && hdr[2]=='L' && hdr[3]=='F')
235-
{
236-
if(!filename.empty())
237-
message.error() << "Sorry, but I can't read ELF binary '" << filename
238-
<< "'" << messaget::eom;
239-
else
240-
message.error() << "Sorry, but I can't read ELF binaries"
241-
<< messaget::eom;
242-
243-
return true;
244-
}
235+
if(!filename.empty())
236+
message.error() << "Sorry, but I can't read ELF binary '" << filename
237+
<< "'" << messaget::eom;
245238
else
246-
{
247-
message.error() << "'" << filename << "' is not a goto-binary"
239+
message.error() << "Sorry, but I can't read ELF binaries"
248240
<< messaget::eom;
249-
return true;
250-
}
251-
}
252-
}
253-
254-
irep_serializationt::ireps_containert ic;
255-
irep_serializationt irepconverter(ic);
256-
// symbol_serializationt symbolconverter(ic);
257241

258-
{
259-
const std::size_t version = irepconverter.read_gb_word(in);
260-
261-
if(version < GOTO_BINARY_VERSION)
262-
{
263-
message.error() <<
264-
"The input was compiled with an old version of "
265-
"goto-cc; please recompile" << messaget::eom;
266242
return true;
267243
}
268-
else if(version == GOTO_BINARY_VERSION)
269-
{
270-
read_bin_goto_object(in, symbol_table, functions, irepconverter);
271-
return false;
272-
}
273244
else
274245
{
275-
message.error() <<
276-
"The input was compiled with an unsupported version of "
277-
"goto-cc; please recompile" << messaget::eom;
246+
message.error() << "'" << filename << "' is not a goto-binary"
247+
<< messaget::eom;
278248
return true;
279249
}
280250
}
281251

282-
UNREACHABLE;
252+
irep_serializationt::ireps_containert ic;
253+
irep_serializationt irepconverter(ic);
254+
255+
const std::size_t version = irepconverter.read_gb_word(in);
256+
257+
if(version < GOTO_BINARY_VERSION)
258+
{
259+
message.error() << "The input was compiled with an old version of "
260+
"goto-cc; please recompile"
261+
<< messaget::eom;
262+
return true;
263+
}
264+
else if(version == GOTO_BINARY_VERSION)
265+
{
266+
read_bin_goto_object(in, symbol_table, functions, irepconverter);
267+
return false;
268+
}
269+
else
270+
{
271+
message.error() << "The input was compiled with an unsupported version of "
272+
"goto-cc; please recompile"
273+
<< messaget::eom;
274+
return true;
275+
}
283276
}

0 commit comments

Comments
 (0)