Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: avoid use-after-move StatusOr #7635

Merged
merged 3 commits into from
Nov 19, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion google/cloud/stream_range.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,18 +169,20 @@ class StreamRange {
private:
void Next() {
// Jump to the end if we previously got an error.
if (!is_end_ && !current_) {
if (!is_end_ && !current_ok_) {
is_end_ = true;
return;
}
struct UnpackVariant {
StreamRange& sr;
void operator()(Status&& status) {
sr.is_end_ = status.ok();
sr.current_ok_ = status.ok();
if (!status.ok()) sr.current_ = std::move(status);
}
void operator()(T&& t) {
sr.is_end_ = false;
sr.current_ok_ = true;
sr.current_ = std::move(t);
}
};
Expand Down Expand Up @@ -224,6 +226,7 @@ class StreamRange {

internal::StreamReader<T> reader_;
StatusOr<T> current_;
bool current_ok_ = false;
bool is_end_ = true;
};

Expand Down