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 builds for older version of libprotobuf #1

Merged
merged 1 commit into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
build/
.vscode/
2 changes: 1 addition & 1 deletion examples/libfuzzer/libfuzzer_bin_example.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ DEFINE_BINARY_PROTO_FUZZER(const libfuzzer_example::Msg& message) {
!std::isnan(message.optional_float()) &&
std::fabs(message.optional_float()) > 1000 &&
message.any().UnpackTo(&file) && !file.name().empty()) {
std::cerr << absl::StrCat(message) << "\n";
std::cerr << message.DebugString() << "\n";
abort();
}
}
2 changes: 1 addition & 1 deletion examples/libfuzzer/libfuzzer_example.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ DEFINE_PROTO_FUZZER(const libfuzzer_example::Msg& message) {
!std::isnan(message.optional_float()) &&
std::fabs(message.optional_float()) > 1000 &&
message.any().UnpackTo(&file) && !file.name().empty()) {
std::cerr << absl::StrCat(message) << "\n";
std::cerr << message.DebugString() << "\n";
abort();
}
}
16 changes: 16 additions & 0 deletions src/field_instance.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,21 @@ class ConstFieldInstance {
return descriptor_->message_type();
}

#if PROTOBUF_VERSION < 3019006
bool EnforceUtf8() const {
return descriptor_->type() == protobuf::FieldDescriptor::TYPE_STRING &&
descriptor()->file()->syntax() ==
protobuf::FileDescriptor::SYNTAX_PROTO3;
}

const protobuf::FieldDescriptor* descriptor() const { return descriptor_; }

std::string DebugString() const {
std::string s = descriptor_->DebugString();
if (is_repeated()) s += "[" + std::to_string(index_) + "]";
return s + " of\n" + message_->DebugString();
}
#else
bool EnforceUtf8() const { return descriptor_->requires_utf8_validation(); }

const protobuf::FieldDescriptor* descriptor() const { return descriptor_; }
Expand All @@ -199,6 +214,7 @@ class ConstFieldInstance {
if (is_repeated()) s += absl::StrCat("[", index_, "]");
return s + " of\n" + absl::StrCat(*message_);
}
#endif

protected:
bool is_repeated() const { return descriptor_->is_repeated(); }
Expand Down
2 changes: 1 addition & 1 deletion src/mutator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -801,7 +801,7 @@ std::string Mutator::MutateUtf8String(const std::string& value,

bool Mutator::IsInitialized(const Message& message) const {
if (!keep_initialized_ || message.IsInitialized()) return true;
std::cerr << "Uninitialized: " << absl::StrCat(message) << "\n";
std::cerr << "Uninitialized: " << message.DebugString() << "\n";
return false;
}

Expand Down
4 changes: 2 additions & 2 deletions src/mutator_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -410,8 +410,8 @@ bool Mutate(const protobuf::Message& from, const protobuf::Message& to,
}

ADD_FAILURE() << "Failed to get from:\n"
<< absl::StrCat(from) << "\nto:\n"
<< absl::StrCat(to);
<< from.DebugString() << "\nto:\n"
<< to.DebugString();
return false;
}

Expand Down