Allow the dispatcher in DescriptorPool to be set to nullptr.

Previously, when we call SetRecursiveBuildDispatcher(nullptr), this created a unique_ptr to an AnyInvocable object with a function pointer to a nullptr, which triggers a segmentation fault inside BuildFile.

PiperOrigin-RevId: 607435995
pull/15855/head
Protobuf Team Bot 10 months ago committed by Copybara-Service
parent 5553de265e
commit 783a023f6a
  1. 10
      src/google/protobuf/descriptor.h

@ -2237,9 +2237,13 @@ class PROTOBUF_EXPORT DescriptorPool {
// Asynchronous execution is undefined behavior. // Asynchronous execution is undefined behavior.
void SetRecursiveBuildDispatcher( void SetRecursiveBuildDispatcher(
absl::AnyInvocable<void(absl::FunctionRef<void()>) const> dispatcher) { absl::AnyInvocable<void(absl::FunctionRef<void()>) const> dispatcher) {
dispatcher_ = std::make_unique< if (dispatcher != nullptr) {
absl::AnyInvocable<void(absl::FunctionRef<void()>) const>>( dispatcher_ = std::make_unique<
std::move(dispatcher)); absl::AnyInvocable<void(absl::FunctionRef<void()>) const>>(
std::move(dispatcher));
} else {
dispatcher_.reset(nullptr);
}
} }
#endif // SWIG #endif // SWIG

Loading…
Cancel
Save