diff options
author | David Tardon <dtardon@redhat.com> | 2013-02-26 14:55:05 +0100 |
---|---|---|
committer | David Tardon <dtardon@redhat.com> | 2013-02-26 15:24:53 +0100 |
commit | 2f1c0be4533dc476fc23b82502360c5abc13906b (patch) | |
tree | 9ab4b15e2a8b255f0cfc69bf97546ec78c041ab2 /helpcompiler | |
parent | fba47cdec494b716131dc6cdff3a750e980ba610 (diff) |
avoid string substr/replace with invalid pos
Change-Id: Iceb9851bcb5e6fe66efd701fcb31e16596fe8b5a
Diffstat (limited to 'helpcompiler')
-rw-r--r-- | helpcompiler/source/HelpCompiler.cxx | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/helpcompiler/source/HelpCompiler.cxx b/helpcompiler/source/HelpCompiler.cxx index eedc7fd660b5..926a6dd86cea 100644 --- a/helpcompiler/source/HelpCompiler.cxx +++ b/helpcompiler/source/HelpCompiler.cxx @@ -95,7 +95,9 @@ void HelpCompiler::saveXhpForJar( xmlDocPtr doc, const fs::path &filePath ) #endif const std::string& sourceXhpPath = filePath.native_file_string(); std::string zipdirPath = zipdir.native_file_string(); - std::string jarXhpPath = sourceXhpPath.substr( sourceXhpPath.rfind( lang + pathSep + "text" + pathSep ) ).substr( lang.length() ); + const std::string srcdirPath( src.native_file_string() ); + // srcdirPath contains trailing /, but we want the file path with / at the beginning + std::string jarXhpPath = sourceXhpPath.substr( srcdirPath.length() - 1 ); std::string xhpFileName = jarXhpPath.substr( jarXhpPath.rfind( pathSep ) + 1 ); jarXhpPath = jarXhpPath.substr( 0, jarXhpPath.rfind( pathSep ) ); if ( !jarXhpPath.compare( 1, 11, "text" + pathSep + "sbasic" ) ) @@ -104,8 +106,9 @@ void HelpCompiler::saveXhpForJar( xmlDocPtr doc, const fs::path &filePath ) } if ( !jarXhpPath.compare( 1, 11, "text" + pathSep + "shared" ) ) { - size_t pos = zipdirPath.find( "ziptmp" ) + 6; - zipdirPath.replace( pos, module.length(), "shared" ); + const size_t pos = zipdirPath.find( "ziptmp" ); + if ( pos != std::string::npos ) + zipdirPath.replace( pos + 6, module.length(), "shared" ); } xmlDocPtr compacted = compactXhpForJar( doc ); fs::create_directory( fs::path( zipdirPath + jarXhpPath, fs::native ) ); |