Skip to content

Commit

Permalink
Merge pull request #1 from isaac-peka/buildfix
Browse files Browse the repository at this point in the history
Fix builds for older version of libprotobuf
  • Loading branch information
isaac-peka authored Feb 16, 2024
2 parents 1f95f80 + 11e7e2e commit 988e0f5
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 5 deletions.
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

0 comments on commit 988e0f5

Please sign in to comment.