From 6933f0150c2850da38783fbdcb60429d314bbc2b Mon Sep 17 00:00:00 2001 From: Michael Tautschnig Date: Mon, 3 Apr 2023 10:48:33 +0000 Subject: [PATCH] Cleanup read_bin_goto_object Remove unnecessary braces that obscure control flow, and remove commented-out code that has no use. --- src/goto-programs/read_bin_goto_object.cpp | 93 ++++++++++------------ 1 file changed, 43 insertions(+), 50 deletions(-) diff --git a/src/goto-programs/read_bin_goto_object.cpp b/src/goto-programs/read_bin_goto_object.cpp index f31f398bc71..b9762cfd1d6 100644 --- a/src/goto-programs/read_bin_goto_object.cpp +++ b/src/goto-programs/read_bin_goto_object.cpp @@ -214,70 +214,63 @@ bool read_bin_goto_object( { messaget message(message_handler); - { - char hdr[4]; - hdr[0]=static_cast(in.get()); - hdr[1]=static_cast(in.get()); - hdr[2]=static_cast(in.get()); + char hdr[4]; + hdr[0] = static_cast(in.get()); + hdr[1] = static_cast(in.get()); + hdr[2] = static_cast(in.get()); - if(hdr[0]=='G' && hdr[1]=='B' && hdr[2]=='F') + if(hdr[0] == 'G' && hdr[1] == 'B' && hdr[2] == 'F') + { + // OK! + } + else + { + hdr[3] = static_cast(in.get()); + if(hdr[0] == 0x7f && hdr[1] == 'G' && hdr[2] == 'B' && hdr[3] == 'F') { // OK! } - else + else if(hdr[0] == 0x7f && hdr[1] == 'E' && hdr[2] == 'L' && hdr[3] == 'F') { - hdr[3]=static_cast(in.get()); - if(hdr[0]==0x7f && hdr[1]=='G' && hdr[2]=='B' && hdr[3]=='F') - { - // OK! - } - else if(hdr[0]==0x7f && hdr[1]=='E' && hdr[2]=='L' && hdr[3]=='F') - { - if(!filename.empty()) - message.error() << "Sorry, but I can't read ELF binary '" << filename - << "'" << messaget::eom; - else - message.error() << "Sorry, but I can't read ELF binaries" - << messaget::eom; - - return true; - } + if(!filename.empty()) + message.error() << "Sorry, but I can't read ELF binary '" << filename + << "'" << messaget::eom; else - { - message.error() << "'" << filename << "' is not a goto-binary" + message.error() << "Sorry, but I can't read ELF binaries" << messaget::eom; - return true; - } - } - } - - irep_serializationt::ireps_containert ic; - irep_serializationt irepconverter(ic); - // symbol_serializationt symbolconverter(ic); - { - const std::size_t version = irepconverter.read_gb_word(in); - - if(version < GOTO_BINARY_VERSION) - { - message.error() << - "The input was compiled with an old version of " - "goto-cc; please recompile" << messaget::eom; return true; } - else if(version == GOTO_BINARY_VERSION) - { - read_bin_goto_object(in, symbol_table, functions, irepconverter); - return false; - } else { - message.error() << - "The input was compiled with an unsupported version of " - "goto-cc; please recompile" << messaget::eom; + message.error() << "'" << filename << "' is not a goto-binary" + << messaget::eom; return true; } } - UNREACHABLE; + irep_serializationt::ireps_containert ic; + irep_serializationt irepconverter(ic); + + const std::size_t version = irepconverter.read_gb_word(in); + + if(version < GOTO_BINARY_VERSION) + { + message.error() << "The input was compiled with an old version of " + "goto-cc; please recompile" + << messaget::eom; + return true; + } + else if(version == GOTO_BINARY_VERSION) + { + read_bin_goto_object(in, symbol_table, functions, irepconverter); + return false; + } + else + { + message.error() << "The input was compiled with an unsupported version of " + "goto-cc; please recompile" + << messaget::eom; + return true; + } }