Skip to content

Commit d5f8199

Browse files
committed
fix: avoid bitwise operations on integers
1 parent 522537b commit d5f8199

File tree

6 files changed

+14
-12
lines changed

6 files changed

+14
-12
lines changed

src/incoming_msg.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Napi::Value IncomingMsg::IntoBuffer(const Napi::Env& env) {
3131
auto length = zmq_msg_size(*ref);
3232

3333
if (noElectronMemoryCage) {
34-
static auto constexpr zero_copy_threshold = 1 << 7;
34+
static auto constexpr zero_copy_threshold = 1U << 7U;
3535
if (length > zero_copy_threshold) {
3636
/* Reuse existing buffer for external storage. This avoids copying but
3737
does include an overhead in having to call a finalizer when the

src/observer.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ constexpr const char* EventName(uint32_t val) {
7777

7878
#ifdef ZMQ_EVENT_HANDSHAKE_FAILED_AUTH
7979
constexpr const char* AuthError(uint32_t val) {
80+
// NOLINTBEGIN(*-magic-numbers)
8081
switch (val) {
8182
case 300:
8283
return "Temporary error";
@@ -88,6 +89,7 @@ constexpr const char* AuthError(uint32_t val) {
8889
/* Fallback if the auth error was unknown, which should not happen. */
8990
return "Unknown error";
9091
}
92+
// NOLINTEND(*-magic-numbers)
9193
}
9294
#endif
9395

@@ -201,13 +203,13 @@ bool Observer::ValidateOpen() const {
201203
}
202204

203205
bool Observer::HasEvents() const {
204-
int32_t events = 0;
206+
uint32_t events = 0;
205207
size_t events_size = sizeof(events);
206208

207209
while (zmq_getsockopt(socket, ZMQ_EVENTS, &events, &events_size) < 0) {
208210
/* Ignore errors. */
209211
if (zmq_errno() != EINTR) {
210-
return 0;
212+
return false;
211213
}
212214
}
213215

src/outgoing_msg.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
namespace zmq {
88
OutgoingMsg::OutgoingMsg(Napi::Value value, Module& module) {
9-
static auto constexpr zero_copy_threshold = 1 << 7;
9+
static auto constexpr zero_copy_threshold = 1U << 7U;
1010

1111
auto buffer_send = [&](uint8_t* data, size_t length) {
1212
/* Zero-copy heuristic. There's an overhead in releasing the buffer with an

src/poller.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class Poller {
1616
UvHandle<uv_timer_t> readable_timer;
1717
UvHandle<uv_timer_t> writable_timer;
1818

19-
int32_t events{0};
19+
uint32_t events{0};
2020
std::function<void()> finalize = nullptr;
2121

2222
public:
@@ -139,7 +139,7 @@ class Poller {
139139
/* Trigger one or more specific events manually. No validation is
140140
performed, which means these will cause EAGAIN errors if no events
141141
were actually available. */
142-
void Trigger(int32_t triggered) {
142+
void Trigger(uint32_t triggered) {
143143
events &= ~triggered;
144144
if (events == 0) {
145145
[[maybe_unused]] auto err = uv_poll_stop(poll);

src/socket.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
namespace zmq {
2121
/* The maximum number of sync I/O operations that are allowed before the I/O
2222
methods will force the returned promise to be resolved in the next tick. */
23-
[[maybe_unused]] auto constexpr max_sync_operations = 1 << 9;
23+
[[maybe_unused]] auto constexpr max_sync_operations = 1U << 9U;
2424

2525
/* Ordinary static cast for all available numeric types. */
2626
template <typename T>
@@ -38,7 +38,7 @@ uint64_t NumberCast<uint64_t>(const Napi::Number& num) {
3838
return 0;
3939
}
4040

41-
static constexpr auto max_safe_integer = static_cast<double>((1ULL << 53) - 1);
41+
static constexpr auto max_safe_integer = static_cast<double>((1ULL << 53U) - 1);
4242
if (value > max_safe_integer) {
4343
Warn(num.Env(),
4444
"Value is larger than Number.MAX_SAFE_INTEGER and may have been rounded "
@@ -245,8 +245,8 @@ bool Socket::ValidateOpen() const {
245245
}
246246
}
247247

248-
bool Socket::HasEvents(int32_t requested) const {
249-
int32_t events = 0;
248+
bool Socket::HasEvents(uint32_t requested_events) const {
249+
uint32_t events = 0;
250250
size_t events_size = sizeof(events);
251251

252252
while (zmq_getsockopt(socket, ZMQ_EVENTS, &events, &events_size) < 0) {
@@ -256,7 +256,7 @@ bool Socket::HasEvents(int32_t requested) const {
256256
}
257257
}
258258

259-
return (events & requested) != 0;
259+
return (events & requested_events) != 0;
260260
}
261261

262262
void Socket::Close() {

src/socket.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class Socket : public Napi::ObjectWrap<Socket>, public Closable {
5656
private:
5757
inline void WarnUnlessImmediateOption(int32_t option) const;
5858
[[nodiscard]] inline bool ValidateOpen() const;
59-
[[nodiscard]] bool HasEvents(int32_t events) const;
59+
[[nodiscard]] bool HasEvents(uint32_t requested_events) const;
6060

6161
/* Send/receive are usually in a hot path and will benefit slightly
6262
from being inlined. They are used in more than one location and are

0 commit comments

Comments
 (0)