Merge lp:~nknotts/dccl/exceptions into lp:~dccl-dev/dccl/3.0

Proposed by Nathan Knotts
Status: Merged
Merged at revision: 317
Proposed branch: lp:~nknotts/dccl/exceptions
Merge into: lp:~dccl-dev/dccl/3.0
Diff against target: 57 lines (+13/-4)
2 files modified
src/bitset.h (+5/-2)
src/codec.cpp (+8/-2)
To merge this branch: bzr merge lp:~nknotts/dccl/exceptions
Reviewer Review Type Date Requested Status
toby schneider Approve
Review via email: mp+254526@code.launchpad.net

Description of the change

I changed the assertions that I previously added to exceptions to match the style of the rest of the code base.

To post a comment you must log in.
lp:~nknotts/dccl/exceptions updated
320. By Nathan Knotts

Merge lp:dccl

Revision history for this message
toby schneider (tes) wrote :

Thanks - looks good to me.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/bitset.h'
2--- src/bitset.h 2015-03-02 14:57:15 +0000
3+++ src/bitset.h 2015-03-30 01:04:57 +0000
4@@ -28,7 +28,6 @@
5 #include <algorithm>
6 #include <limits>
7 #include <string>
8-#include <cassert>
9 #include <cstring>
10
11 #include "exception.h"
12@@ -325,12 +324,16 @@
13 /// \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]
14 /// \param max_len Maximum length of buf
15 /// \return number of bytes written to buf
16+ /// \throw std::length_error if max_len < encoded length.
17 size_t to_byte_string(char* buf, size_t max_len)
18 {
19 // number of bytes needed is ceil(size() / 8)
20 size_t len = this->size()/8 + (this->size()%8 ? 1 : 0);
21
22- assert( max_len >= len );
23+ if (max_len < len)
24+ {
25+ throw std::length_error("max_len must be >= len");
26+ }
27
28 // initialize buffer to all zeroes
29 std::fill_n(buf, len, 0);
30
31=== modified file 'src/codec.cpp'
32--- src/codec.cpp 2015-01-20 20:20:52 +0000
33+++ src/codec.cpp 2015-03-30 01:04:57 +0000
34@@ -219,7 +219,10 @@
35 encode_internal(msg, header_only, head_bits, body_bits);
36
37 size_t head_byte_size = ceil_bits2bytes(head_bits.size());
38- assert(max_len >= head_byte_size);
39+ if (max_len < head_byte_size)
40+ {
41+ throw std::length_error("max_len must be >= head_byte_size");
42+ }
43 head_bits.to_byte_string(bytes, head_byte_size);
44
45 dlog.is(DEBUG2, ENCODE) && dlog << "Head bytes (bits): " << head_byte_size << "(" << head_bits.size() << ")" << std::endl;
46@@ -230,7 +233,10 @@
47 if (!header_only)
48 {
49 body_byte_size = ceil_bits2bytes(body_bits.size());
50- assert(max_len >= head_byte_size + body_byte_size);
51+ if (max_len < (head_byte_size + body_byte_size))
52+ {
53+ throw std::length_error("max_len must be >= (head_byte_size + body_byte_size)");
54+ }
55 body_bits.to_byte_string(bytes+head_byte_size, max_len-head_byte_size);
56
57 dlog.is(DEBUG3, ENCODE) && dlog << "Unencrypted Body (bin): " << body_bits << std::endl;

Subscribers

People subscribed via source and target branches

to all changes: