Mailinglist Archive: zypp-devel (75 mails)
| < Previous | Next > |
Re: [zypp-devel] Re: [zypp-commit] r10158 - IMO undefined behaviour.
- From: Josef Reidinger <jreidinger@xxxxxxx>
- Date: Thu, 29 May 2008 12:46:59 +0200
- Message-id: <483E89A3.1010801@xxxxxxx>
Michael Andres wrote:
Thanks for fix, I little overdo elimination of duplicate code.
Pepa
--
To unsubscribe, e-mail: zypp-devel+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: zypp-devel+help@xxxxxxxxxxxx
Date: Tue May 20 12:11:28 2008
New Revision: 10158
URL: http://svn.opensuse.org/viewcvs/zypp?rev=10158&view=rev
Log:
allow installation and refresh from repository with alias that contains ' or " (bnc #392426)
+ const char *toFile =
str::gsub(solvfile.asString(),"\"","\\\"").c_str();
if ( repokind.toEnum() == RepoType::RPMPLAINDIR_e )
{
- cmd << str::form( "repo2solv.sh \"%s\" > \"%s\"",
info.baseUrlsBegin()->getPathName().c_str(), solvfile.c_str() );
+ const char * from = str::gsub(
+ info.baseUrlsBegin()->getPathName(),"\"","\\\"").c_str();
+ cmd << str::form( "repo2solv.sh \"%s\" > \"%s\"", from , toFile );
const char *toFile = str::gsub(...).c_str();
Is IMO not efficient but undefined behaviour!
c_str() returns a pointer to the std::strings internal data. Any string manipulation (incl. going out of scope) may invalidate the char*.
std::strings are cheap to copy and .c_str() is most probably inlined, so you don't lose performance if you take care the string actually stays in
memory:
std::string toFile = str::gsub(..);
or better
std::string toFile( str::gsub(..) );
Otherwise you have to do it this way:
cmd << str::form( "repo2solv.sh \"%s\" > \"%s\"", str::gsub( info.baseUrlsBegin()->getPathName(),"\"","\\\"").c_str(),
str::gsub( solvfile.asString(),"\"","\\\"").c_str() );
(I'll fix it)
Thanks for fix, I little overdo elimination of duplicate code.
Pepa
--
To unsubscribe, e-mail: zypp-devel+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: zypp-devel+help@xxxxxxxxxxxx
| < Previous | Next > |