diff options
author | Caolán McNamara <caolanm@redhat.com> | 2015-11-06 10:00:03 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2015-11-06 12:16:01 +0000 |
commit | f3c77010ce650570ce0819fd262a164c47b7f6a7 (patch) | |
tree | 7357c0dbcb783feb7ff3dbfbd6572676e4a25a31 /helpcompiler | |
parent | 0b3a807eadb8cb1e25556ddc25c9b722527314bb (diff) |
coverity#1338271 Uncaught exception
Change-Id: Ib2b7617f9862b904bd3d5939800244c541eba8a5
Diffstat (limited to 'helpcompiler')
-rw-r--r-- | helpcompiler/source/HelpIndexer_main.cxx | 105 |
1 files changed, 57 insertions, 48 deletions
diff --git a/helpcompiler/source/HelpIndexer_main.cxx b/helpcompiler/source/HelpIndexer_main.cxx index 97b1d7a17910..85ff29a39b9d 100644 --- a/helpcompiler/source/HelpIndexer_main.cxx +++ b/helpcompiler/source/HelpIndexer_main.cxx @@ -16,70 +16,79 @@ #include "LuceneHelper.hxx" -int main(int argc, char **argv) { - const std::string pLang("-lang"); - const std::string pModule("-mod"); - const std::string pDir("-dir"); +int main(int argc, char **argv) +{ + try + { + const std::string pLang("-lang"); + const std::string pModule("-mod"); + const std::string pDir("-dir"); - std::string lang; - std::string module; - std::string dir; + std::string lang; + std::string module; + std::string dir; - bool error = false; - for (int i = 1; i < argc; ++i) { - if (pLang.compare(argv[i]) == 0) { - if (i + 1 < argc) { - lang = argv[++i]; + bool error = false; + for (int i = 1; i < argc; ++i) { + if (pLang.compare(argv[i]) == 0) { + if (i + 1 < argc) { + lang = argv[++i]; + } else { + error = true; + } + } else if (pModule.compare(argv[i]) == 0) { + if (i + 1 < argc) { + module = argv[++i]; + } else { + error = true; + } + } else if (pDir.compare(argv[i]) == 0) { + if (i + 1 < argc) { + dir = argv[++i]; + } else { + error = true; + } } else { error = true; } - } else if (pModule.compare(argv[i]) == 0) { - if (i + 1 < argc) { - module = argv[++i]; - } else { - error = true; - } - } else if (pDir.compare(argv[i]) == 0) { - if (i + 1 < argc) { - dir = argv[++i]; - } else { - error = true; - } - } else { - error = true; } - } - if (error) { - std::cerr << "Error parsing command-line arguments" << std::endl; - } + if (error) { + std::cerr << "Error parsing command-line arguments" << std::endl; + } - if (error || lang.empty() || module.empty() || dir.empty()) { - std::cerr << "Usage: HelpIndexer -lang ISOLangCode -mod HelpModule -dir Dir" << std::endl; - return 1; - } + if (error || lang.empty() || module.empty() || dir.empty()) { + std::cerr << "Usage: HelpIndexer -lang ISOLangCode -mod HelpModule -dir Dir" << std::endl; + return 1; + } - OUString sDir; + OUString sDir; - osl::File::getFileURLFromSystemPath( - OUString(dir.c_str(), dir.size(), osl_getThreadTextEncoding()), - sDir); + osl::File::getFileURLFromSystemPath( + OUString(dir.c_str(), dir.size(), osl_getThreadTextEncoding()), + sDir); - OUString cwd; - osl_getProcessWorkingDir(&cwd.pData); + OUString cwd; + osl_getProcessWorkingDir(&cwd.pData); - osl::File::getAbsoluteFileURL(cwd, sDir, sDir); + osl::File::getAbsoluteFileURL(cwd, sDir, sDir); - HelpIndexer indexer( - OUString(lang.c_str(), lang.size(), osl_getThreadTextEncoding()), - OUString(module.c_str(), module.size(), osl_getThreadTextEncoding()), - sDir, sDir); + HelpIndexer indexer( + OUString(lang.c_str(), lang.size(), osl_getThreadTextEncoding()), + OUString(module.c_str(), module.size(), osl_getThreadTextEncoding()), + sDir, sDir); - if (!indexer.indexDocuments()) { - std::cerr << OUStringToOString(indexer.getErrorMessage(), osl_getThreadTextEncoding()).getStr() << std::endl; + if (!indexer.indexDocuments()) { + std::cerr << OUStringToOString(indexer.getErrorMessage(), osl_getThreadTextEncoding()).getStr() << std::endl; + return 2; + } + return 0; + } + catch (std::exception& e) + { + std::cerr << "failure: " << e.what() << std::endl; return 2; } - return 0; } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |