From 7ed36e0d7beb71667e70dcf256a3a610e839073b Mon Sep 17 00:00:00 2001 From: Caolán McNamara Date: Thu, 23 Oct 2014 16:21:54 +0100 Subject: coverity#441992 Uncaught exception Change-Id: Ibd07b854bbcf9d9e83236669addfd61fe639882a --- idlc/source/idlcmain.cxx | 211 ++++++++++++++++++++++++----------------------- 1 file changed, 106 insertions(+), 105 deletions(-) (limited to 'idlc') diff --git a/idlc/source/idlcmain.cxx b/idlc/source/idlcmain.cxx index 52e05f0eb247..270bf7a193a1 100644 --- a/idlc/source/idlcmain.cxx +++ b/idlc/source/idlcmain.cxx @@ -35,131 +35,132 @@ SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv) } Options options(argv[0]); + sal_Int32 nErrors = 0; + try { if (!options.initOptions(args)) return (0); - } - catch(const IllegalArgument& e) - { - fprintf(stderr, "Illegal argument: %s\n%s", - e.m_message.getStr(), - options.prepareVersion().getStr()); - return (99); - } - - setIdlc(&options); - sal_Int32 nErrors = 0; - if (options.readStdin()) { - if ( !options.quiet() ) - fprintf( - stdout, "%s: Compiling stdin\n", - options.getProgramName().getStr()); - nErrors = compileFile(0); - if ( ( idlc()->getWarningCount() > 0 ) && !options.quiet() ) { - fprintf( - stdout, "%s: detected %lu warnings compiling stdin\n", - options.getProgramName().getStr(), - sal::static_int_cast< unsigned long >( - idlc()->getWarningCount())); - } - OString outputUrl; - if (options.isValid("-O")) { - outputUrl = convertToFileUrl(options.getOption("-O")); - if (!outputUrl.endsWith("/")) { - outputUrl += "/"; + setIdlc(&options); + + if (options.readStdin()) { + if ( !options.quiet() ) + fprintf( + stdout, "%s: Compiling stdin\n", + options.getProgramName().getStr()); + nErrors = compileFile(0); + if ( ( idlc()->getWarningCount() > 0 ) && !options.quiet() ) { + fprintf( + stdout, "%s: detected %lu warnings compiling stdin\n", + options.getProgramName().getStr(), + sal::static_int_cast< unsigned long >( + idlc()->getWarningCount())); + } + OString outputUrl; + if (options.isValid("-O")) { + outputUrl = convertToFileUrl(options.getOption("-O")); + if (!outputUrl.endsWith("/")) { + outputUrl += "/"; + } + outputUrl += "stdin.urd"; + } else { + outputUrl = convertToFileUrl("stdin.urd"); } - outputUrl += "stdin.urd"; - } else { - outputUrl = convertToFileUrl("stdin.urd"); + if (nErrors > 0) { + removeIfExists(outputUrl); + } else { + nErrors = produceFile(outputUrl, 0); + } + idlc()->reset(); } - if (nErrors > 0) { - removeIfExists(outputUrl); - } else { - nErrors = produceFile(outputUrl, 0); + StringVector const & files = options.getInputFiles(); + if ( options.verbose() ) + { + fprintf( stdout, "%s: compiling %i source files ... \n", + options.getProgramName().getStr(), (int)files.size() ); + fflush( stdout ); } - idlc()->reset(); - } - StringVector const & files = options.getInputFiles(); - if ( options.verbose() ) - { - fprintf( stdout, "%s: compiling %i source files ... \n", - options.getProgramName().getStr(), (int)files.size() ); - fflush( stdout ); - } - for (StringVector::const_iterator i(files.begin()); - i != files.end() && nErrors == 0; ++i) - { - OString sysFileName( convertToAbsoluteSystemPath(*i) ); - - if ( !options.quiet() ) - fprintf(stdout, "Compiling: %s\n", - (*i).getStr()); - nErrors = compileFile(&sysFileName); + for (StringVector::const_iterator i(files.begin()); + i != files.end() && nErrors == 0; ++i) + { + OString sysFileName( convertToAbsoluteSystemPath(*i) ); - if ( idlc()->getWarningCount() && !options.quiet() ) - fprintf(stdout, "%s: detected %lu warnings compiling file '%s'\n", - options.getProgramName().getStr(), - sal::static_int_cast< unsigned long >( - idlc()->getWarningCount()), + if ( !options.quiet() ) + fprintf(stdout, "Compiling: %s\n", (*i).getStr()); - - // prepare output file name - OString const strippedFileName( - sysFileName.copy(sysFileName.lastIndexOf(SEPARATOR) + 1)); - OString outputFile; - if ( options.isValid("-O") ) - { - outputFile = (options.getOption("-O")); - if (!outputFile.endsWith("/")) { - outputFile += OString('/'); + nErrors = compileFile(&sysFileName); + + if ( idlc()->getWarningCount() && !options.quiet() ) + fprintf(stdout, "%s: detected %lu warnings compiling file '%s'\n", + options.getProgramName().getStr(), + sal::static_int_cast< unsigned long >( + idlc()->getWarningCount()), + (*i).getStr()); + + // prepare output file name + OString const strippedFileName( + sysFileName.copy(sysFileName.lastIndexOf(SEPARATOR) + 1)); + OString outputFile; + if ( options.isValid("-O") ) + { + outputFile = (options.getOption("-O")); + if (!outputFile.endsWith("/")) { + outputFile += OString('/'); + } + outputFile += strippedFileName.replaceAt( + strippedFileName.getLength() -3 , 3, "urd"); + } else { + outputFile = + sysFileName.replaceAt(sysFileName.getLength() -3 , 3, "urd"); } - outputFile += strippedFileName.replaceAt( - strippedFileName.getLength() -3 , 3, "urd"); - } else { - outputFile = - sysFileName.replaceAt(sysFileName.getLength() -3 , 3, "urd"); - } - OString const outputFileUrl = convertToFileUrl(outputFile); + OString const outputFileUrl = convertToFileUrl(outputFile); - OString depFileUrl; - if (options.isValid("-M")) { - depFileUrl = convertToFileUrl(options.getOption("-M")); - if (!depFileUrl.endsWith("/")) { - depFileUrl += "/"; + OString depFileUrl; + if (options.isValid("-M")) { + depFileUrl = convertToFileUrl(options.getOption("-M")); + if (!depFileUrl.endsWith("/")) { + depFileUrl += "/"; + } + depFileUrl += strippedFileName.replaceAt( + strippedFileName.getLength() -3 , 3, "d"); } - depFileUrl += strippedFileName.replaceAt( - strippedFileName.getLength() -3 , 3, "d"); - } - if ( nErrors ) { - if (options.isValid("-M")) { - removeIfExists(depFileUrl); + if ( nErrors ) { + if (options.isValid("-M")) { + removeIfExists(depFileUrl); + } + removeIfExists(outputFileUrl); + } else { + sPair_t const pair(depFileUrl, outputFile); + nErrors = produceFile(outputFileUrl, + (options.isValid("-M")) ? &pair : 0); } - removeIfExists(outputFileUrl); - } else { - sPair_t const pair(depFileUrl, outputFile); - nErrors = produceFile(outputFileUrl, - (options.isValid("-M")) ? &pair : 0); - } - idlc()->reset(); - } + idlc()->reset(); + } - if ( nErrors > 0 ) - { - fprintf(stderr, "%s: detected %ld errors%s", - options.getProgramName().getStr(), - sal::static_int_cast< long >(nErrors), - options.prepareVersion().getStr()); - } else - { - if ( options.verbose() ) - fprintf(stdout, "%s: returned successful%s", + if ( nErrors > 0 ) + { + fprintf(stderr, "%s: detected %ld errors%s", options.getProgramName().getStr(), + sal::static_int_cast< long >(nErrors), options.prepareVersion().getStr()); + } else + { + if ( options.verbose() ) + fprintf(stdout, "%s: returned successful%s", + options.getProgramName().getStr(), + options.prepareVersion().getStr()); + } + } catch(const IllegalArgument& e) + { + fprintf(stderr, "Illegal argument: %s\n%s", + e.m_message.getStr(), + options.prepareVersion().getStr()); + return (99); } + return nErrors; } -- cgit