From bb9988365f1e50f1dc170a5905566bf7b9c09b5c Mon Sep 17 00:00:00 2001 From: Austin Schuh Date: Sat, 28 Nov 2015 13:12:30 -0800 Subject: [PATCH] Fixed const correctness in casts and unused parameters. GCC was throwing warnings about const correctness issues and unused parameters. This patch gets rid of those warnings by using the correct casts. --- src/WireDecoder.cpp | 16 ++++++++-------- src/WireDecoder.h | 14 +++++++------- src/leb128.cpp | 2 +- src/networktables/NetworkTable.cpp | 10 +++++----- 4 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/WireDecoder.cpp b/src/WireDecoder.cpp index 1e7d32a7f4..138225e2d7 100644 --- a/src/WireDecoder.cpp +++ b/src/WireDecoder.cpp @@ -19,28 +19,28 @@ using namespace nt; static double ReadDouble(const char*& buf) { // Fast but non-portable! - std::uint64_t val = (*((unsigned char*)buf)) & 0xff; + std::uint64_t val = (*reinterpret_cast(buf)) & 0xff; ++buf; val <<= 8; - val |= (*((unsigned char*)buf)) & 0xff; + val |= (*reinterpret_cast(buf)) & 0xff; ++buf; val <<= 8; - val |= (*((unsigned char*)buf)) & 0xff; + val |= (*reinterpret_cast(buf)) & 0xff; ++buf; val <<= 8; - val |= (*((unsigned char*)buf)) & 0xff; + val |= (*reinterpret_cast(buf)) & 0xff; ++buf; val <<= 8; - val |= (*((unsigned char*)buf)) & 0xff; + val |= (*reinterpret_cast(buf)) & 0xff; ++buf; val <<= 8; - val |= (*((unsigned char*)buf)) & 0xff; + val |= (*reinterpret_cast(buf)) & 0xff; ++buf; val <<= 8; - val |= (*((unsigned char*)buf)) & 0xff; + val |= (*reinterpret_cast(buf)) & 0xff; ++buf; val <<= 8; - val |= (*((unsigned char*)buf)) & 0xff; + val |= (*reinterpret_cast(buf)) & 0xff; ++buf; return llvm::BitsToDouble(val); } diff --git a/src/WireDecoder.h b/src/WireDecoder.h index cb56da29d1..c520be7b71 100644 --- a/src/WireDecoder.h +++ b/src/WireDecoder.h @@ -74,7 +74,7 @@ class WireDecoder { bool Read8(unsigned int* val) { const char* buf; if (!Read(&buf, 1)) return false; - *val = (*((unsigned char*)buf)) & 0xff; + *val = (*reinterpret_cast(buf)) & 0xff; return true; } @@ -82,10 +82,10 @@ class WireDecoder { bool Read16(unsigned int* val) { const char* buf; if (!Read(&buf, 2)) return false; - unsigned int v = (*((unsigned char*)buf)) & 0xff; + unsigned int v = (*reinterpret_cast(buf)) & 0xff; ++buf; v <<= 8; - v |= (*((unsigned char*)buf)) & 0xff; + v |= (*reinterpret_cast(buf)) & 0xff; *val = v; return true; } @@ -94,16 +94,16 @@ class WireDecoder { bool Read32(unsigned long* val) { const char* buf; if (!Read(&buf, 4)) return false; - unsigned int v = (*((unsigned char*)buf)) & 0xff; + unsigned int v = (*reinterpret_cast(buf)) & 0xff; ++buf; v <<= 8; - v |= (*((unsigned char*)buf)) & 0xff; + v |= (*reinterpret_cast(buf)) & 0xff; ++buf; v <<= 8; - v |= (*((unsigned char*)buf)) & 0xff; + v |= (*reinterpret_cast(buf)) & 0xff; ++buf; v <<= 8; - v |= (*((unsigned char*)buf)) & 0xff; + v |= (*reinterpret_cast(buf)) & 0xff; *val = v; return true; } diff --git a/src/leb128.cpp b/src/leb128.cpp index a79c3bfa6c..3e99842bec 100644 --- a/src/leb128.cpp +++ b/src/leb128.cpp @@ -72,7 +72,7 @@ std::size_t ReadUleb128(const char* addr, unsigned long* ret) { std::size_t count = 0; while (1) { - unsigned char byte = *((unsigned char*)addr); + unsigned char byte = *reinterpret_cast(addr); addr++; count++; diff --git a/src/networktables/NetworkTable.cpp b/src/networktables/NetworkTable.cpp index 7a1e6114f2..a2f5790af8 100644 --- a/src/networktables/NetworkTable.cpp +++ b/src/networktables/NetworkTable.cpp @@ -115,8 +115,8 @@ void NetworkTable::AddTableListenerEx(ITableListener* listener, std::size_t prefix_len = path.size(); unsigned int id = nt::AddEntryListener( path, - [=](unsigned int uid, StringRef name, std::shared_ptr value, - unsigned int flags_) { + [=](unsigned int /*uid*/, StringRef name, + std::shared_ptr value, unsigned int flags_) { StringRef relative_key = name.substr(prefix_len); if (relative_key.find(PATH_SEPARATOR_CHAR) != StringRef::npos) return; listener->ValueChangedEx(this, relative_key, value, flags_); @@ -141,7 +141,7 @@ void NetworkTable::AddTableListenerEx(StringRef key, ITableListener* listener, path += key; unsigned int id = nt::AddEntryListener( path, - [=](unsigned int uid, StringRef name, std::shared_ptr value, + [=](unsigned int /*uid*/, StringRef name, std::shared_ptr value, unsigned int flags_) { if (name != path) return; listener->ValueChangedEx(this, name.substr(prefix_len), value, flags_); @@ -169,8 +169,8 @@ void NetworkTable::AddSubTableListener(ITableListener* listener, if (localNotify) flags |= NT_NOTIFY_LOCAL; unsigned int id = nt::AddEntryListener( path, - [=](unsigned int uid, StringRef name, std::shared_ptr value, - unsigned int flags_) mutable { + [=](unsigned int /*uid*/, StringRef name, + std::shared_ptr /*value*/, unsigned int flags_) mutable { StringRef relative_key = name.substr(prefix_len); auto end_sub_table = relative_key.find(PATH_SEPARATOR_CHAR); if (end_sub_table == StringRef::npos) return;