diff options
author | Tor Brede Vekterli <vekterli@oath.com> | 2018-07-25 14:24:21 +0000 |
---|---|---|
committer | Tor Brede Vekterli <vekterli@oath.com> | 2018-07-25 14:24:21 +0000 |
commit | 12c8f3005e202b31a8e0ff3816ce9d714a269046 (patch) | |
tree | a5d9ba0eedc49df2cea2dbdfea677c4c37ed3775 /messagebus | |
parent | e3af3d215feb1e416b27b92bbf421dde281f3a09 (diff) |
Remove stringref::c_str()
The expected semantics of c_str() (a null-terminated string) cannot
be satisfied with a string reference, so remove the function entirely
to prevent people from using it in buggy ways.
Replaces c_str() with data() in places where it is presumed safe,
otherwise constructs temporary string instances. Certain callsites
have been de-stringref'd in favor of regular strings, in particular
where C APIs have been transitively called. The vast majority of
these were called with string parameters anyway, so should not
cause much extra allocation.
Diffstat (limited to 'messagebus')
-rw-r--r-- | messagebus/src/vespa/messagebus/network/rpcsend.cpp | 8 | ||||
-rw-r--r-- | messagebus/src/vespa/messagebus/routing/routeparser.cpp | 5 |
2 files changed, 7 insertions, 6 deletions
diff --git a/messagebus/src/vespa/messagebus/network/rpcsend.cpp b/messagebus/src/vespa/messagebus/network/rpcsend.cpp index 04cccd59903..87c87173ec7 100644 --- a/messagebus/src/vespa/messagebus/network/rpcsend.cpp +++ b/messagebus/src/vespa/messagebus/network/rpcsend.cpp @@ -207,12 +207,12 @@ RPCSend::decode(vespalib::stringref protocolName, const vespalib::Version & vers } } else { error = Error(ErrorCode::DECODE_ERROR, - make_string("Protocol '%s' failed to decode routable.", protocolName.c_str())); + make_string("Protocol '%s' failed to decode routable.", vespalib::string(protocolName).c_str())); } } else { error = Error(ErrorCode::UNKNOWN_PROTOCOL, - make_string("Protocol '%s' is not known by %s.", protocolName.c_str(), _serverIdent.c_str())); + make_string("Protocol '%s' is not known by %s.", vespalib::string(protocolName).c_str(), _serverIdent.c_str())); } return reply; } @@ -263,7 +263,7 @@ RPCSend::invoke(FRT_RPCRequest *req) if (protocol == nullptr) { replyError(req, params->getVersion(), params->getTraceLevel(), Error(ErrorCode::UNKNOWN_PROTOCOL, make_string("Protocol '%s' is not known by %s.", - params->getProtocol().c_str(), _serverIdent.c_str()))); + vespalib::string(params->getProtocol()).c_str(), _serverIdent.c_str()))); return; } if (protocol->requireSequencing() || !_net->allowDispatchForDecode()) { @@ -284,7 +284,7 @@ RPCSend::doRequest(FRT_RPCRequest *req, const IProtocol * protocol, std::unique_ if ( ! routable ) { replyError(req, params->getVersion(), params->getTraceLevel(), Error(ErrorCode::DECODE_ERROR, - make_string("Protocol '%s' failed to decode routable.", params->getProtocol().c_str()))); + make_string("Protocol '%s' failed to decode routable.", vespalib::string(params->getProtocol()).c_str()))); return; } if (routable->isReply()) { diff --git a/messagebus/src/vespa/messagebus/routing/routeparser.cpp b/messagebus/src/vespa/messagebus/routing/routeparser.cpp index 3bc9b57d1e7..0fb90f0d585 100644 --- a/messagebus/src/vespa/messagebus/routing/routeparser.cpp +++ b/messagebus/src/vespa/messagebus/routing/routeparser.cpp @@ -34,8 +34,9 @@ RouteParser::createTcpDirective(const stringref &str) if (posS == string::npos || posS == posP + 1) { return IHopDirective::SP(); // no port } + // FIXME C++17 range-safe from_chars() instead of atoi() return IHopDirective::SP(new TcpDirective(str.substr(0, posP), - atoi(str.substr(posP + 1, posS - 1).c_str()), + atoi(str.substr(posP + 1, posS - 1).data()), str.substr(posS + 1))); } @@ -104,7 +105,7 @@ RouteParser::createHop(stringref str) return Hop().addDirective(createErrorDirective( vespalib::make_string( "Failed to completely parse '%s'.", - str.c_str()))); + vespalib::string(str).c_str()))); } else if (str[at] == '[') { ++depth; } else if (str[at] == ']') { |