This is an automated email from the ASF dual-hosted git repository.
alexey pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kudu.git
The following commit(s) were added to refs/heads/master by this push:
new 3722ed49c [net] make SockAddr::HashCode() return size_t
3722ed49c is described below
commit 3722ed49c19ce54c7feae2fa944e32b1d4ed8d2d
Author: Alexey Serbin <[email protected]>
AuthorDate: Fri Jan 16 19:24:57 2026 -0800
[net] make SockAddr::HashCode() return size_t
This patch changes the return type of SockAddr::HashCode() from uint32_t
to size_t (since the underlying hash function effectively operates with
64-bit integers on x86_64 anyway) and brings more consistency into
the specialization of the std::hash<T>::operator()(const T&) for the
Sockaddr type. This addresses UBSAN warnings on implicit conversion of
integers (when enabled) and makes SockAddr::HashCode() consistent with
the expectations for std::hash<T>::operator() template specialization.
Change-Id: Ia228dfd6cf932a2378ba7e7cafbc07a381313c12
Reviewed-on: http://gerrit.cloudera.org:8080/23876
Tested-by: Alexey Serbin <[email protected]>
Reviewed-by: Abhishek Chennaka <[email protected]>
---
src/kudu/util/net/sockaddr.cc | 2 +-
src/kudu/util/net/sockaddr.h | 10 +++++-----
2 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/src/kudu/util/net/sockaddr.cc b/src/kudu/util/net/sockaddr.cc
index 6f19f5e58..3105bc18b 100644
--- a/src/kudu/util/net/sockaddr.cc
+++ b/src/kudu/util/net/sockaddr.cc
@@ -290,7 +290,7 @@ void Sockaddr::set_length(socklen_t len) {
sizeof(storage_) - len_);
}
-uint32_t Sockaddr::HashCode() const {
+size_t Sockaddr::HashCode() const {
return HashStringThoroughly(reinterpret_cast<const char*>(&storage_), len_);
}
diff --git a/src/kudu/util/net/sockaddr.h b/src/kudu/util/net/sockaddr.h
index 82a1eac6c..4fa9906a7 100644
--- a/src/kudu/util/net/sockaddr.h
+++ b/src/kudu/util/net/sockaddr.h
@@ -14,13 +14,14 @@
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
-#ifndef KUDU_UTIL_NET_SOCKADDR_H
-#define KUDU_UTIL_NET_SOCKADDR_H
+
+#pragma once
#include <netinet/in.h>
#include <sys/socket.h>
#include <sys/un.h>
+#include <cstddef>
#include <cstdint>
#include <string>
#include <utility>
@@ -68,7 +69,7 @@ class Sockaddr {
// family and have the same bytewise representation. Two uninitialized
addresses
// are equal to each other but not to any other address.
bool operator==(const Sockaddr& other) const;
- uint32_t HashCode() const;
+ size_t HashCode() const;
// Compare two addresses bytewise.
//
@@ -219,9 +220,8 @@ class Sockaddr {
namespace std {
template<>
struct hash<kudu::Sockaddr> {
- int operator()(const kudu::Sockaddr& addr) const {
+ size_t operator()(const kudu::Sockaddr& addr) const {
return addr.HashCode();
}
};
} // namespace std
-#endif