dccl-dev team mailing list archive
-
dccl-dev team
-
Mailing list archive
-
Message #00025
[Merge] lp:~nknotts/dccl/exceptions into lp:dccl
Nathan Knotts has proposed merging lp:~nknotts/dccl/exceptions into lp:dccl.
Requested reviews:
DCCL Developers (dccl-dev)
For more details, see:
https://code.launchpad.net/~nknotts/dccl/exceptions/+merge/254526
I changed the assertions that I previously added to exceptions to match the style of the rest of the code base.
--
Your team DCCL Developers is requested to review the proposed merge of lp:~nknotts/dccl/exceptions into lp:dccl.
=== modified file 'src/bitset.h'
--- src/bitset.h 2015-03-02 14:57:15 +0000
+++ src/bitset.h 2015-03-30 00:56:52 +0000
@@ -28,8 +28,11 @@
#include <algorithm>
#include <limits>
#include <string>
+<<<<<<< TREE
#include <cassert>
#include <cstring>
+=======
+>>>>>>> MERGE-SOURCE
#include "exception.h"
@@ -325,12 +328,16 @@
/// \param buf An output string containing the value of the Bitset, with the least signficant byte in string[0] and the most significant byte in string[size()-1]
/// \param max_len Maximum length of buf
/// \return number of bytes written to buf
+ /// \throw std::length_error if max_len < encoded length.
size_t to_byte_string(char* buf, size_t max_len)
{
// number of bytes needed is ceil(size() / 8)
size_t len = this->size()/8 + (this->size()%8 ? 1 : 0);
- assert( max_len >= len );
+ if (max_len < len)
+ {
+ throw std::length_error("max_len must be >= len");
+ }
// initialize buffer to all zeroes
std::fill_n(buf, len, 0);
=== modified file 'src/codec.cpp'
--- src/codec.cpp 2015-01-20 20:20:52 +0000
+++ src/codec.cpp 2015-03-30 00:56:52 +0000
@@ -219,7 +219,10 @@
encode_internal(msg, header_only, head_bits, body_bits);
size_t head_byte_size = ceil_bits2bytes(head_bits.size());
- assert(max_len >= head_byte_size);
+ if (max_len < head_byte_size)
+ {
+ throw std::length_error("max_len must be >= head_byte_size");
+ }
head_bits.to_byte_string(bytes, head_byte_size);
dlog.is(DEBUG2, ENCODE) && dlog << "Head bytes (bits): " << head_byte_size << "(" << head_bits.size() << ")" << std::endl;
@@ -230,7 +233,10 @@
if (!header_only)
{
body_byte_size = ceil_bits2bytes(body_bits.size());
- assert(max_len >= head_byte_size + body_byte_size);
+ if (max_len < (head_byte_size + body_byte_size))
+ {
+ throw std::length_error("max_len must be >= (head_byte_size + body_byte_size)");
+ }
body_bits.to_byte_string(bytes+head_byte_size, max_len-head_byte_size);
dlog.is(DEBUG3, ENCODE) && dlog << "Unencrypted Body (bin): " << body_bits << std::endl;
Follow ups