From 143c915f348d3db791b6b27f7e21a2a4762e6039 Mon Sep 17 00:00:00 2001 From: Christoph Egger Date: Wed, 25 Mar 2015 13:40:51 +0100 Subject: [PATCH] Proper error handling when opening binary Fail properly when the supplied file is not a recognized binary Closes T25 --- src/disassembler/llvm/LLVMDisassembler.cxx | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/disassembler/llvm/LLVMDisassembler.cxx b/src/disassembler/llvm/LLVMDisassembler.cxx index b97f93f..8ffb417 100644 --- a/src/disassembler/llvm/LLVMDisassembler.cxx +++ b/src/disassembler/llvm/LLVMDisassembler.cxx @@ -27,12 +27,22 @@ namespace { * */ Disassembler * createLLVMDisassembler(const std::string& filename, InformationManager* manager) { + log4cxx::LoggerPtr logger(log4cxx::Logger::getLogger("disassembler.LLVMDisassembler")); if (filename == "") return NULL; - std::unique_ptr o; - o.reset(createBinary(filename).get()); - Binary * op = o.release(); + auto retval = createBinary(filename); + if (error_code ec = retval.getError()) { + LOG4CXX_ERROR(logger, ec.message()); + return NULL; + } + + Binary * op = retval.get(); + + if (!op) { + LOG4CXX_ERROR(logger, "Could not open " << filename); + return NULL; + } // ELFType if (ELF32LEObjectFile * object = dyn_cast(op)) { -- 2.39.5