Commit 7c2d1c18 authored by Simon Giesecke's avatar Simon Giesecke

Problem: magic literals for UCHAR_MAX

Solution: use UCHAR_MAX constant instead
parent a4c817e7
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include "precompiled.hpp" #include "precompiled.hpp"
#include <string.h> #include <string.h>
#include <limits.h>
#include "mechanism.hpp" #include "mechanism.hpp"
#include "options.hpp" #include "options.hpp"
...@@ -124,7 +125,7 @@ static size_t property_len (size_t name_len_, size_t value_len_) ...@@ -124,7 +125,7 @@ static size_t property_len (size_t name_len_, size_t value_len_)
static size_t name_len (const char *name_) static size_t name_len (const char *name_)
{ {
const size_t name_len = strlen (name_); const size_t name_len = strlen (name_);
zmq_assert (name_len <= 255); zmq_assert (name_len <= UCHAR_MAX);
return name_len; return name_len;
} }
......
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include "precompiled.hpp" #include "precompiled.hpp"
#include <string.h> #include <string.h>
#include <limits.h>
#include <set> #include <set>
#include "options.hpp" #include "options.hpp"
...@@ -491,7 +492,7 @@ int zmq::options_t::setsockopt (int option_, ...@@ -491,7 +492,7 @@ int zmq::options_t::setsockopt (int option_,
case ZMQ_TCP_ACCEPT_FILTER: { case ZMQ_TCP_ACCEPT_FILTER: {
std::string filter_str; std::string filter_str;
int rc = do_setsockopt_string_allow_empty_strict ( int rc = do_setsockopt_string_allow_empty_strict (
optval_, optvallen_, &filter_str, 255); optval_, optvallen_, &filter_str, UCHAR_MAX);
if (rc == 0) { if (rc == 0) {
if (filter_str.empty ()) { if (filter_str.empty ()) {
tcp_accept_filters.clear (); tcp_accept_filters.clear ();
...@@ -559,7 +560,7 @@ int zmq::options_t::setsockopt (int option_, ...@@ -559,7 +560,7 @@ int zmq::options_t::setsockopt (int option_,
case ZMQ_ZAP_DOMAIN: case ZMQ_ZAP_DOMAIN:
return do_setsockopt_string_allow_empty_relaxed ( return do_setsockopt_string_allow_empty_relaxed (
optval_, optvallen_, &zap_domain, 255); optval_, optvallen_, &zap_domain, UCHAR_MAX);
break; break;
// If curve encryption isn't built, these options provoke EINVAL // If curve encryption isn't built, these options provoke EINVAL
......
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
#include "precompiled.hpp" #include "precompiled.hpp"
#include "macros.hpp" #include "macros.hpp"
#include <limits.h>
#include <string.h> #include <string.h>
#ifndef ZMQ_HAVE_WINDOWS #ifndef ZMQ_HAVE_WINDOWS
...@@ -232,7 +233,7 @@ void zmq::stream_engine_t::plug (io_thread_t *io_thread_, ...@@ -232,7 +233,7 @@ void zmq::stream_engine_t::plug (io_thread_t *io_thread_,
// Send the 'length' and 'flags' fields of the routing id message. // Send the 'length' and 'flags' fields of the routing id message.
// The 'length' field is encoded in the long format. // The 'length' field is encoded in the long format.
_outpos = _greeting_send; _outpos = _greeting_send;
_outpos[_outsize++] = 0xff; _outpos[_outsize++] = UCHAR_MAX;
put_uint64 (&_outpos[_outsize], _options.routing_id_size + 1); put_uint64 (&_outpos[_outsize], _options.routing_id_size + 1);
_outsize += 8; _outsize += 8;
_outpos[_outsize++] = 0x7f; _outpos[_outsize++] = 0x7f;
...@@ -587,7 +588,8 @@ bool zmq::stream_engine_t::handshake () ...@@ -587,7 +588,8 @@ bool zmq::stream_engine_t::handshake ()
// Since there is no way to tell the encoder to // Since there is no way to tell the encoder to
// skip the message header, we simply throw that // skip the message header, we simply throw that
// header data away. // header data away.
const size_t header_size = _options.routing_id_size + 1 >= 255 ? 10 : 2; const size_t header_size =
_options.routing_id_size + 1 >= UCHAR_MAX ? 10 : 2;
unsigned char tmp[10], *bufferp = tmp; unsigned char tmp[10], *bufferp = tmp;
// Prepare the routing id message and load it into encoder. // Prepare the routing id message and load it into encoder.
......
...@@ -146,7 +146,7 @@ void zmq::thread_t:: ...@@ -146,7 +146,7 @@ void zmq::thread_t::
{ {
int priority = int priority =
(_thread_priority >= 0 ? _thread_priority : DEFAULT_PRIORITY); (_thread_priority >= 0 ? _thread_priority : DEFAULT_PRIORITY);
priority = (priority < 255 ? priority : DEFAULT_PRIORITY); priority = (priority < UCHAR_MAX ? priority : DEFAULT_PRIORITY);
if (_descriptor != NULL || _descriptor > 0) { if (_descriptor != NULL || _descriptor > 0) {
taskPrioritySet (_descriptor, priority); taskPrioritySet (_descriptor, priority);
} }
......
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <limits> #include <limits>
#include <limits.h>
#include "decoder.hpp" #include "decoder.hpp"
#include "v1_decoder.hpp" #include "v1_decoder.hpp"
...@@ -57,10 +58,10 @@ zmq::v1_decoder_t::~v1_decoder_t () ...@@ -57,10 +58,10 @@ zmq::v1_decoder_t::~v1_decoder_t ()
int zmq::v1_decoder_t::one_byte_size_ready (unsigned char const *) int zmq::v1_decoder_t::one_byte_size_ready (unsigned char const *)
{ {
// First byte of size is read. If it is 0xff read 8-byte size. // First byte of size is read. If it is UCHAR_MAX (0xff) read 8-byte size.
// Otherwise allocate the buffer for message data and read the // Otherwise allocate the buffer for message data and read the
// message data into it. // message data into it.
if (*_tmpbuf == 0xff) if (*_tmpbuf == UCHAR_MAX)
next_step (_tmpbuf, 8, &v1_decoder_t::eight_byte_size_ready); next_step (_tmpbuf, 8, &v1_decoder_t::eight_byte_size_ready);
else { else {
// There has to be at least one byte (the flags) in the message). // There has to be at least one byte (the flags) in the message).
......
...@@ -33,6 +33,8 @@ ...@@ -33,6 +33,8 @@
#include "msg.hpp" #include "msg.hpp"
#include "wire.hpp" #include "wire.hpp"
#include <limits.h>
zmq::v1_encoder_t::v1_encoder_t (size_t bufsize_) : zmq::v1_encoder_t::v1_encoder_t (size_t bufsize_) :
encoder_base_t<v1_encoder_t> (bufsize_) encoder_base_t<v1_encoder_t> (bufsize_)
{ {
...@@ -62,12 +64,12 @@ void zmq::v1_encoder_t::message_ready () ...@@ -62,12 +64,12 @@ void zmq::v1_encoder_t::message_ready ()
// For messages less than 255 bytes long, write one byte of message size. // For messages less than 255 bytes long, write one byte of message size.
// For longer messages write 0xff escape character followed by 8-byte // For longer messages write 0xff escape character followed by 8-byte
// message size. In both cases 'flags' field follows. // message size. In both cases 'flags' field follows.
if (size < 255) { if (size < UCHAR_MAX) {
_tmpbuf[0] = static_cast<unsigned char> (size); _tmpbuf[0] = static_cast<unsigned char> (size);
_tmpbuf[1] = (in_progress->flags () & msg_t::more); _tmpbuf[1] = (in_progress->flags () & msg_t::more);
next_step (_tmpbuf, 2, &v1_encoder_t::size_ready, false); next_step (_tmpbuf, 2, &v1_encoder_t::size_ready, false);
} else { } else {
_tmpbuf[0] = 0xff; _tmpbuf[0] = UCHAR_MAX;
put_uint64 (_tmpbuf + 1, size); put_uint64 (_tmpbuf + 1, size);
_tmpbuf[9] = (in_progress->flags () & msg_t::more); _tmpbuf[9] = (in_progress->flags () & msg_t::more);
next_step (_tmpbuf, 10, &v1_encoder_t::size_ready, false); next_step (_tmpbuf, 10, &v1_encoder_t::size_ready, false);
......
...@@ -34,6 +34,8 @@ ...@@ -34,6 +34,8 @@
#include "likely.hpp" #include "likely.hpp"
#include "wire.hpp" #include "wire.hpp"
#include <limits.h>
zmq::v2_encoder_t::v2_encoder_t (size_t bufsize_) : zmq::v2_encoder_t::v2_encoder_t (size_t bufsize_) :
encoder_base_t<v2_encoder_t> (bufsize_) encoder_base_t<v2_encoder_t> (bufsize_)
{ {
...@@ -52,7 +54,7 @@ void zmq::v2_encoder_t::message_ready () ...@@ -52,7 +54,7 @@ void zmq::v2_encoder_t::message_ready ()
protocol_flags = 0; protocol_flags = 0;
if (in_progress->flags () & msg_t::more) if (in_progress->flags () & msg_t::more)
protocol_flags |= v2_protocol_t::more_flag; protocol_flags |= v2_protocol_t::more_flag;
if (in_progress->size () > 255) if (in_progress->size () > UCHAR_MAX)
protocol_flags |= v2_protocol_t::large_flag; protocol_flags |= v2_protocol_t::large_flag;
if (in_progress->flags () & msg_t::command) if (in_progress->flags () & msg_t::command)
protocol_flags |= v2_protocol_t::command_flag; protocol_flags |= v2_protocol_t::command_flag;
...@@ -61,7 +63,7 @@ void zmq::v2_encoder_t::message_ready () ...@@ -61,7 +63,7 @@ void zmq::v2_encoder_t::message_ready ()
// the length is encoded as 8-bit unsigned integer. For larger // the length is encoded as 8-bit unsigned integer. For larger
// messages, 64-bit unsigned integer in network byte order is used. // messages, 64-bit unsigned integer in network byte order is used.
const size_t size = in_progress->size (); const size_t size = in_progress->size ();
if (unlikely (size > 255)) { if (unlikely (size > UCHAR_MAX)) {
put_uint64 (_tmp_buf + 1, size); put_uint64 (_tmp_buf + 1, size);
next_step (_tmp_buf, 9, &v2_encoder_t::size_ready, false); next_step (_tmp_buf, 9, &v2_encoder_t::size_ready, false);
} else { } else {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment