summaryrefslogtreecommitdiff
path: root/registry/tools
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2015-11-06 09:41:26 +0000
committerCaolán McNamara <caolanm@redhat.com>2015-11-06 12:15:55 +0000
commit77a03426517ae5e39ad32a4e62c90b630dde1b27 (patch)
tree59dc82045ebe4de79152dda9b46577a6a71b626a /registry/tools
parente995c817dd8a2a9e476dde4dfb3b041d0c50c408 (diff)
coverity#1338252 Uncaught exception
Change-Id: Ia058e42700c7724efd74fd6c5560ccca919fb2e8
Diffstat (limited to 'registry/tools')
-rw-r--r--registry/tools/regmerge.cxx111
1 files changed, 60 insertions, 51 deletions
diff --git a/registry/tools/regmerge.cxx b/registry/tools/regmerge.cxx
index 3a929c942c8c..b7e4a5058d3a 100644
--- a/registry/tools/regmerge.cxx
+++ b/registry/tools/regmerge.cxx
@@ -86,84 +86,93 @@ int main( int argc, char * argv[] )
int __cdecl main( int argc, char * argv[] )
#endif
{
- Options_Impl options(argv[0]);
-
- std::vector< std::string > args;
- for (int i = 1; i < argc; i++)
+ try
{
- if (!Options::checkArgument(args, argv[i], strlen(argv[i])))
+ Options_Impl options(argv[0]);
+
+ std::vector< std::string > args;
+ for (int i = 1; i < argc; i++)
+ {
+ if (!Options::checkArgument(args, argv[i], strlen(argv[i])))
+ {
+ options.printUsage();
+ return 1;
+ }
+ }
+ if (!options.initOptions(args))
+ {
+ return 1;
+ }
+ if (args.size() < 3)
{
options.printUsage();
return 1;
}
- }
- if (!options.initOptions(args))
- {
- return 1;
- }
- if (args.size() < 3)
- {
- options.printUsage();
- return 1;
- }
- Registry reg;
- OUString regName( convertToFileUrl(args[0].c_str(), args[0].size()) );
- if (reg.open(regName, RegAccessMode::READWRITE) != RegError::NO_ERROR)
- {
- if (reg.create(regName) != RegError::NO_ERROR)
+ Registry reg;
+ OUString regName( convertToFileUrl(args[0].c_str(), args[0].size()) );
+ if (reg.open(regName, RegAccessMode::READWRITE) != RegError::NO_ERROR)
{
- if (options.isVerbose())
- fprintf(stderr, "open registry \"%s\" failed\n", args[0].c_str());
- return -1;
+ if (reg.create(regName) != RegError::NO_ERROR)
+ {
+ if (options.isVerbose())
+ fprintf(stderr, "open registry \"%s\" failed\n", args[0].c_str());
+ return -1;
+ }
}
- }
- RegistryKey rootKey;
- if (reg.openRootKey(rootKey) != RegError::NO_ERROR)
- {
- if (options.isVerbose())
- fprintf(stderr, "open root key of registry \"%s\" failed\n", args[0].c_str());
- return -4;
- }
+ RegistryKey rootKey;
+ if (reg.openRootKey(rootKey) != RegError::NO_ERROR)
+ {
+ if (options.isVerbose())
+ fprintf(stderr, "open root key of registry \"%s\" failed\n", args[0].c_str());
+ return -4;
+ }
- OUString mergeKeyName( OUString::createFromAscii(args[1].c_str()) );
- for (size_t i = 2; i < args.size(); i++)
- {
- OUString targetRegName( convertToFileUrl(args[i].c_str(), args[i].size()) );
- RegError _ret = reg.mergeKey(rootKey, mergeKeyName, targetRegName, false, options.isVerbose());
- if (_ret != RegError::NO_ERROR)
+ OUString mergeKeyName( OUString::createFromAscii(args[1].c_str()) );
+ for (size_t i = 2; i < args.size(); i++)
{
- if (_ret == RegError::MERGE_CONFLICT)
+ OUString targetRegName( convertToFileUrl(args[i].c_str(), args[i].size()) );
+ RegError _ret = reg.mergeKey(rootKey, mergeKeyName, targetRegName, false, options.isVerbose());
+ if (_ret != RegError::NO_ERROR)
{
- if (options.isVerbose())
- fprintf(stderr, "merging registry \"%s\" under key \"%s\" in registry \"%s\".\n",
- args[i].c_str(), args[1].c_str(), args[0].c_str());
+ if (_ret == RegError::MERGE_CONFLICT)
+ {
+ if (options.isVerbose())
+ fprintf(stderr, "merging registry \"%s\" under key \"%s\" in registry \"%s\".\n",
+ args[i].c_str(), args[1].c_str(), args[0].c_str());
+ }
+ else
+ {
+ if (options.isVerbose())
+ fprintf(stderr, "ERROR: merging registry \"%s\" under key \"%s\" in registry \"%s\" failed.\n",
+ args[i].c_str(), args[1].c_str(), args[0].c_str());
+ return -2;
+ }
}
else
{
if (options.isVerbose())
- fprintf(stderr, "ERROR: merging registry \"%s\" under key \"%s\" in registry \"%s\" failed.\n",
+ fprintf(stderr, "merging registry \"%s\" under key \"%s\" in registry \"%s\".\n",
args[i].c_str(), args[1].c_str(), args[0].c_str());
- return -2;
}
}
- else
+
+ rootKey.releaseKey();
+ if (reg.close() != RegError::NO_ERROR)
{
if (options.isVerbose())
- fprintf(stderr, "merging registry \"%s\" under key \"%s\" in registry \"%s\".\n",
- args[i].c_str(), args[1].c_str(), args[0].c_str());
+ fprintf(stderr, "closing registry \"%s\" failed\n", args[0].c_str());
+ return -5;
}
}
-
- rootKey.releaseKey();
- if (reg.close() != RegError::NO_ERROR)
+ catch (const std::exception &e)
{
- if (options.isVerbose())
- fprintf(stderr, "closing registry \"%s\" failed\n", args[0].c_str());
+ SAL_WARN("registry", "Fatal exception: " << e.what());
return -5;
}
+
return 0;
}