This is the mail archive of the cygwin-apps mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [Patch] Proxy command-line argument


Dave Korn wrote:

+ std::string proxyString(((std::string)ProxyOption).c_str());


I'm not a C++ expert, so maybe I'm missing something, but if I read that
right you're taking ProxyOption (type StringOption), calling the std::string
conversion operator to return a std::string, getting a const char* from that
and using it to build a std::string.

Your non-expert eyes have seen aright. It is either circumlocutious, or broken. If ProxyOption has operator std::string, this does the same thing:


std::string proxyString(ProxyOption);

If it doesn't, the code will still compile because he's using a brute-force C style cast here. But, it would almost certainly crash.

Actually, there's a third possibility: the original author needs to truncate the string at the first embedded null character. The direct std::string copy will preserve a null.

+ std::string proxyString((std::string)ProxyOption);

Just to reinforce the point, the cast is either unhelpful or harmful. If you really must force the conversion, use one of the new-style C++ casts to limit the amount of damage.



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]