From cd567820300912b3d784c06d05b1440a4e4ffb87 Mon Sep 17 00:00:00 2001 From: David Li Date: Tue, 5 Feb 2019 09:37:04 -0500 Subject: [PATCH] Warn about undefined behavior in Flight source --- cpp/src/arrow/flight/client.cc | 2 ++ cpp/src/arrow/flight/server.cc | 7 ++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/cpp/src/arrow/flight/client.cc b/cpp/src/arrow/flight/client.cc index 77c12eee90a5f..af4af60f6580b 100644 --- a/cpp/src/arrow/flight/client.cc +++ b/cpp/src/arrow/flight/client.cc @@ -75,6 +75,7 @@ class FlightStreamReader : public RecordBatchReader { } // For customizing read path for better memory/serialization efficiency + // XXX this cast is undefined behavior auto custom_reader = reinterpret_cast*>(stream_.get()); // Explicitly specify the override to invoke - otherwise compiler @@ -126,6 +127,7 @@ class FlightPutWriter::FlightPutWriterImpl : public ipc::RecordBatchWriter { Status WriteRecordBatch(const RecordBatch& batch, bool allow_64bit = false) override { IpcPayload payload; RETURN_NOT_OK(ipc::internal::GetRecordBatchPayload(batch, pool_, &payload)); + // XXX this cast is undefined behavior auto custom_writer = reinterpret_cast*>(writer_.get()); // Explicitly specify the override to invoke - otherwise compiler // may invoke through vtable (not updated by reinterpret_cast) diff --git a/cpp/src/arrow/flight/server.cc b/cpp/src/arrow/flight/server.cc index b2f24fe525325..0788952c2d340 100644 --- a/cpp/src/arrow/flight/server.cc +++ b/cpp/src/arrow/flight/server.cc @@ -73,6 +73,7 @@ class FlightMessageReaderImpl : public FlightMessageReader { return Status::OK(); } + // XXX this cast is undefined behavior auto custom_reader = reinterpret_cast*>(reader_); FlightData data; @@ -184,6 +185,7 @@ class FlightServiceImpl : public FlightService::Service { GRPC_RETURN_NOT_OK(server_->DoGet(ticket, &data_stream)); // Requires ServerWriter customization in grpc_customizations.h + // XXX this cast is undefined behavior auto custom_writer = reinterpret_cast*>(writer); // Write the schema as the first message in the stream @@ -192,7 +194,10 @@ class FlightServiceImpl : public FlightService::Service { ipc::DictionaryMemo dictionary_memo; GRPC_RETURN_NOT_OK(ipc::internal::GetSchemaPayload( *data_stream->schema(), pool, &dictionary_memo, &schema_payload)); - custom_writer->Write(schema_payload, grpc::WriteOptions()); + // Explicitly specify the override to invoke - otherwise compiler + // may invoke through vtable (not updated by reinterpret_cast) + custom_writer->grpc::ServerWriter::Write(schema_payload, + grpc::WriteOptions()); while (true) { IpcPayload payload;