Skip to content

Commit 5c46b62

Browse files
committed
Fixes narrowing conversion.
NOTE: I had to disable the TLS tests because I shotdown the server I was running on my domain occase.de. Once this ticket is merged I will open a new one to fix that and reenable the tests.
1 parent 6cde6ea commit 5c46b62

File tree

4 files changed

+16
-9
lines changed

4 files changed

+16
-9
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -702,6 +702,14 @@ https://lists.boost.org/Archives/boost/2023/01/253944.php.
702702
Sets `"default"` as the default value of `config::username`. This
703703
makes it simpler to use the `requirepass` configuration in Redis.
704704

705+
* ([Issue 189](https://github.com/boostorg/redis/issues/189)).
706+
Fixes narrowing convertion by using `std::size_t` instead of
707+
`std::uint64_t` for the sizes of bulks and aggregates. The code
708+
relies now on `std::from_chars` returning an error if a value
709+
greater than 32 is received on platforms on which the size
710+
of`std::size_t` is 32.
711+
712+
705713
### Boost 1.84 (First release in Boost)
706714

707715
* Deprecates the `async_receive` overload that takes a response. Users

include/boost/redis/resp3/impl/parser.ipp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2018-2023 Marcelo Zimbres Silva ([email protected])
1+
/* Copyright (c) 2018-2024 Marcelo Zimbres Silva ([email protected])
22
*
33
* Distributed under the Boost Software License, Version 1.0. (See
44
* accompanying file LICENSE.txt)
@@ -13,7 +13,7 @@
1313

1414
namespace boost::redis::resp3 {
1515

16-
void to_int(int_type& i, std::string_view sv, system::error_code& ec)
16+
void to_int(std::size_t& i, std::string_view sv, system::error_code& ec)
1717
{
1818
auto const res = std::from_chars(sv.data(), sv.data() + std::size(sv), i);
1919
if (res.ec != std::errc())
@@ -29,7 +29,7 @@ void parser::reset()
2929
{
3030
depth_ = 0;
3131
sizes_ = {{1}};
32-
bulk_length_ = (std::numeric_limits<unsigned long>::max)();
32+
bulk_length_ = (std::numeric_limits<std::size_t>::max)();
3333
bulk_ = type::invalid;
3434
consumed_ = 0;
3535
sizes_[0] = 2; // The sentinel must be more than 1.
@@ -189,7 +189,7 @@ parser::consume_impl(
189189
case type::attribute:
190190
case type::map:
191191
{
192-
int_type l = -1;
192+
std::size_t l = -1;
193193
to_int(l, elem, ec);
194194
if (ec)
195195
return {};

include/boost/redis/resp3/parser.hpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2018-2023 Marcelo Zimbres Silva ([email protected])
1+
/* Copyright (c) 2018-2024 Marcelo Zimbres Silva ([email protected])
22
*
33
* Distributed under the Boost Software License, Version 1.0. (See
44
* accompanying file LICENSE.txt)
@@ -16,8 +16,6 @@
1616

1717
namespace boost::redis::resp3 {
1818

19-
using int_type = std::uint64_t;
20-
2119
class parser {
2220
public:
2321
using node_type = basic_node<std::string_view>;
@@ -38,7 +36,7 @@ class parser {
3836
std::array<std::size_t, max_embedded_depth + 1> sizes_;
3937

4038
// Contains the length expected in the next bulk read.
41-
int_type bulk_length_;
39+
std::size_t bulk_length_;
4240

4341
// The type of the next bulk. Contains type::invalid if no bulk is
4442
// expected.

test/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ macro(make_test TEST_NAME STANDARD)
3030
endmacro()
3131

3232
make_test(test_conn_quit 17)
33-
make_test(test_conn_tls 17)
33+
# TODO: Configure a Redis server with TLS in the CI and reenable this test.
34+
#make_test(test_conn_tls 17)
3435
make_test(test_low_level 17)
3536
make_test(test_conn_exec_retry 17)
3637
make_test(test_conn_exec_error 17)

0 commit comments

Comments
 (0)