Skip to content

Commit

Permalink
fix(spanner): avoid evaluation-order issue in function arguments
Browse files Browse the repository at this point in the history
The behavior of
```
  extern void f(std::unique_ptr<T>, T);
  std::unique_ptr<T> p = ...;
  f(std::move(p), *p);
```
is undefined, so introduce a sequence point between dereferencing
the `unique_ptr` and moving it.
  • Loading branch information
devbww committed Jul 11, 2022
1 parent 5e15ecb commit bc6ad2b
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions google/cloud/spanner/internal/connection_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -469,9 +469,10 @@ spanner::RowStream ConnectionImpl::ReadImpl(
tracing_options](std::string const& resume_token) mutable {
if (!resume_token.empty()) request->set_resume_token(resume_token);
auto context = absl::make_unique<grpc::ClientContext>();
auto grpc_reader = stub->StreamingRead(*context, *request);
std::unique_ptr<PartialResultSetReader> reader =
absl::make_unique<DefaultPartialResultSetReader>(
std::move(context), stub->StreamingRead(*context, *request));
std::move(context), std::move(grpc_reader));
if (tracing_enabled) {
reader = absl::make_unique<LoggingResultSetReader>(std::move(reader),
tracing_options);
Expand Down Expand Up @@ -688,9 +689,10 @@ ResultType ConnectionImpl::CommonQueryImpl(
tracing_options](std::string const& resume_token) mutable {
if (!resume_token.empty()) request.set_resume_token(resume_token);
auto context = absl::make_unique<grpc::ClientContext>();
auto grpc_reader = stub->ExecuteStreamingSql(*context, request);
std::unique_ptr<PartialResultSetReader> reader =
absl::make_unique<DefaultPartialResultSetReader>(
std::move(context), stub->ExecuteStreamingSql(*context, request));
std::move(context), std::move(grpc_reader));
if (tracing_enabled) {
reader = absl::make_unique<LoggingResultSetReader>(std::move(reader),
tracing_options);
Expand Down

0 comments on commit bc6ad2b

Please sign in to comment.