Skip to content

Commit 6e66d60

Browse files
committed
Fix: Remove invalid uses of copy_cast<> for libuv pointer aliasing
1 parent a5fb25e commit 6e66d60

File tree

9 files changed

+20
-25
lines changed

9 files changed

+20
-25
lines changed

src/async_queue.hpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
#ifndef __CASS_ASYNC_QUEUE_HPP_INCLUDED__
1818
#define __CASS_ASYNC_QUEUE_HPP_INCLUDED__
1919

20-
#include "utils.hpp"
21-
2220
#include <uv.h>
2321

2422
namespace cass {
@@ -35,7 +33,7 @@ class AsyncQueue {
3533
}
3634

3735
void close_handles() {
38-
uv_close(copy_cast<uv_async_t*, uv_handle_t*>(&async_), NULL);
36+
uv_close(reinterpret_cast<uv_handle_t*>(&async_), NULL);
3937
}
4038

4139
void send() {

src/connection.cpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
#include "error_response.hpp"
3535
#include "event_response.hpp"
3636
#include "logger.hpp"
37-
#include "utils.hpp"
3837

3938
#ifdef HAVE_NOSIGPIPE
4039
#include <sys/socket.h>
@@ -344,14 +343,14 @@ void Connection::internal_close(ConnectionState close_state) {
344343

345344
if (state_ != CONNECTION_STATE_CLOSE &&
346345
state_ != CONNECTION_STATE_CLOSE_DEFUNCT) {
347-
uv_handle_t* handle = copy_cast<uv_tcp_t*, uv_handle_t*>(&socket_);
346+
uv_handle_t* handle = reinterpret_cast<uv_handle_t*>(&socket_);
348347
if (!uv_is_closing(handle)) {
349348
heartbeat_timer_.stop();
350349
terminate_timer_.stop();
351350
connect_timer_.stop();
352351
if (state_ == CONNECTION_STATE_CONNECTED ||
353352
state_ == CONNECTION_STATE_READY) {
354-
uv_read_stop(copy_cast<uv_tcp_t*, uv_stream_t*>(&socket_));
353+
uv_read_stop(reinterpret_cast<uv_stream_t*>(&socket_));
355354
}
356355
set_state(close_state);
357356
uv_close(handle, on_close);
@@ -530,23 +529,23 @@ void Connection::on_connect(Connector* connector) {
530529
connection->host_->address_string().c_str(),
531530
static_cast<void*>(connection));
532531

533-
#ifdef HAVE_NOSIGPIPE
532+
#if defined(HAVE_NOSIGPIPE) && UV_VERSION_MAJOR >= 1
534533
// This must be done after connection for the socket file descriptor to be
535534
// valid.
536535
uv_os_fd_t fd = 0;
537536
int enabled = 1;
538-
if (uv_fileno(copy_cast<uv_tcp_t*, uv_handle_t*>(&connection->socket_), &fd) != 0 ||
537+
if (uv_fileno(reinterpret_cast<uv_handle_t*>(&connection->socket_), &fd) != 0 ||
539538
setsockopt(fd, SOL_SOCKET, SO_NOSIGPIPE, (void *)&enabled, sizeof(int)) != 0) {
540539
LOG_WARN("Unable to set socket option SO_NOSIGPIPE for host %s",
541540
connection->host_->address_string().c_str());
542541
}
543542
#endif
544543

545544
if (connection->ssl_session_) {
546-
uv_read_start(copy_cast<uv_tcp_t*, uv_stream_t*>(&connection->socket_),
545+
uv_read_start(reinterpret_cast<uv_stream_t*>(&connection->socket_),
547546
Connection::alloc_buffer_ssl, Connection::on_read_ssl);
548547
} else {
549-
uv_read_start(copy_cast<uv_tcp_t*, uv_stream_t*>(&connection->socket_),
548+
uv_read_start(reinterpret_cast<uv_stream_t*>(&connection->socket_),
550549
Connection::alloc_buffer, Connection::on_read);
551550
}
552551

@@ -1036,7 +1035,7 @@ void Connection::PendingWrite::flush() {
10361035
}
10371036

10381037
is_flushed_ = true;
1039-
uv_stream_t* sock_stream = copy_cast<uv_tcp_t*, uv_stream_t*>(&connection_->socket_);
1038+
uv_stream_t* sock_stream = reinterpret_cast<uv_stream_t*>(&connection_->socket_);
10401039
uv_write(&req_, sock_stream, bufs.data(), bufs.size(), PendingWrite::on_write);
10411040
}
10421041
}
@@ -1106,7 +1105,7 @@ void Connection::PendingWriteSsl::flush() {
11061105

11071106
LOG_TRACE("Sending %u encrypted bytes", static_cast<unsigned int>(encrypted_size_));
11081107

1109-
uv_stream_t* sock_stream = copy_cast<uv_tcp_t*, uv_stream_t*>(&connection_->socket_);
1108+
uv_stream_t* sock_stream = reinterpret_cast<uv_stream_t*>(&connection_->socket_);
11101109
uv_write(&req_, sock_stream, bufs.data(), bufs.size(), PendingWriteSsl::on_write);
11111110

11121111
is_flushed_ = true;
@@ -1123,7 +1122,7 @@ void Connection::PendingWriteSsl::on_write(uv_write_t* req, int status) {
11231122

11241123
bool Connection::SslHandshakeWriter::write(Connection* connection, char* buf, size_t buf_size) {
11251124
SslHandshakeWriter* writer = new SslHandshakeWriter(connection, buf, buf_size);
1126-
uv_stream_t* stream = copy_cast<uv_tcp_t*, uv_stream_t*>(&connection->socket_);
1125+
uv_stream_t* stream = reinterpret_cast<uv_stream_t*>(&connection->socket_);
11271126

11281127
int rc = uv_write(&writer->req_, stream, &writer->uv_buf_, 1, SslHandshakeWriter::on_write);
11291128
if (rc != 0) {

src/io_worker.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ void IOWorker::close_handles() {
244244
EventThread<IOWorkerEvent>::close_handles();
245245
request_queue_.close_handles();
246246
uv_prepare_stop(&prepare_);
247-
uv_close(copy_cast<uv_prepare_t*, uv_handle_t*>(&prepare_), NULL);
247+
uv_close(reinterpret_cast<uv_handle_t*>(&prepare_), NULL);
248248
}
249249

250250
void IOWorker::on_event(const IOWorkerEvent& event) {

src/loop_thread.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ class LoopThread {
9292
void close_handles() {
9393
#if defined(HAVE_SIGTIMEDWAIT) && !defined(HAVE_NOSIGPIPE)
9494
uv_prepare_stop(&prepare_);
95-
uv_close(copy_cast<uv_prepare_t*, uv_handle_t*>(&prepare_), NULL);
95+
uv_close(reinterpret_cast<uv_handle_t*>(&prepare_), NULL);
9696
#endif
9797
}
9898

src/mpmc_queue.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424

2525
#include "atomic.hpp"
2626
#include "cassconfig.hpp"
27-
#include "utils.hpp"
2827
#include "macros.hpp"
28+
#include "utils.hpp"
2929

3030
#include <assert.h>
3131

src/periodic_task.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class PeriodicTask : public RefCounted<PeriodicTask> {
4646

4747
private:
4848
static void close(PeriodicTask* task) {
49-
uv_close(copy_cast<uv_timer_t*, uv_handle_t*>(&task->timer_handle_), on_close);
49+
uv_close(reinterpret_cast<uv_handle_t*>(&task->timer_handle_), on_close);
5050
}
5151

5252
#if UV_VERSION_MAJOR == 0

src/resolver.hpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
#include "address.hpp"
2727
#include "ref_counted.hpp"
2828
#include "timer.hpp"
29-
#include "utils.hpp"
3029

3130
namespace cass {
3231

@@ -100,7 +99,7 @@ class Resolver {
10099
static void on_timeout(Timer* timer) {
101100
Resolver* resolver = static_cast<Resolver*>(timer->data());
102101
resolver->status_ = FAILED_TIMED_OUT;
103-
uv_cancel(copy_cast<uv_getaddrinfo_t*, uv_req_t*>(&resolver->req_));
102+
uv_cancel(reinterpret_cast<uv_req_t*>(&resolver->req_));
104103
}
105104

106105
private:
@@ -208,7 +207,7 @@ class NameResolver {
208207
static void on_timeout(Timer* timer) {
209208
NameResolver* resolver = static_cast<NameResolver*>(timer->data());
210209
resolver->status_ = FAILED_TIMED_OUT;
211-
uv_cancel(copy_cast<uv_getnameinfo_t*, uv_req_t*>(&resolver->req_));
210+
uv_cancel(reinterpret_cast<uv_req_t*>(&resolver->req_));
212211
}
213212

214213
private:

src/spsc_queue.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131

3232
#include "atomic.hpp"
3333
#include "cassconfig.hpp"
34-
#include "utils.hpp"
3534
#include "macros.hpp"
35+
#include "utils.hpp"
3636

3737
namespace cass {
3838

src/timer.hpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#define __CASS_TIMER_HPP_INCLUDED__
1919

2020
#include "macros.hpp"
21-
#include "utils.hpp"
2221

2322
#include <uv.h>
2423

@@ -40,7 +39,7 @@ class Timer {
4039

4140
bool is_running() const {
4241
if (handle_ == NULL) return false;
43-
return uv_is_active(copy_cast<uv_timer_t*, uv_handle_t*>(handle_)) != 0;
42+
return uv_is_active(reinterpret_cast<uv_handle_t*>(handle_)) != 0;
4443
}
4544

4645
void start(uv_loop_t* loop, uint64_t timeout, void* data,
@@ -58,7 +57,7 @@ class Timer {
5857
void stop() {
5958
if (handle_ == NULL) return;
6059
// This also stops the timer
61-
uv_close(copy_cast<uv_timer_t*, uv_handle_t*>(handle_), on_close);
60+
uv_close(reinterpret_cast<uv_handle_t*>(handle_), on_close);
6261
handle_ = NULL;
6362
}
6463

@@ -78,7 +77,7 @@ class Timer {
7877
}
7978

8079
static void on_close(uv_handle_t* handle) {
81-
delete copy_cast<uv_handle_t*, uv_timer_t*>(handle);
80+
delete reinterpret_cast<uv_timer_t*>(handle);
8281
}
8382

8483
private:

0 commit comments

Comments
 (0)