diff options
author | Jacob Gilbert <jacob.gilbert@sandia.gov> | 2016-02-08 07:36:01 -0800 |
---|---|---|
committer | Johnathan Corgan <johnathan@corganlabs.com> | 2016-02-08 07:42:11 -0800 |
commit | 0f9bab7c0e46e029cbe1864cfd766dc7a80897ef (patch) | |
tree | 6e9b1f1cb919789bdc2794473c1e2f7effba39f0 | |
parent | 1e232b237e210be17ad635b53a78017cd6778a75 (diff) |
blocks: fix incorrect use of items/bytes in PDU handling
For a uniform vector, calls to pmt::length return the number
of items in in the vector. However, in some places this was
being treated as a byte value, resulting in short writes and
other misinterpretations.
These calls have been replaced with calls to pmt::blob_length,
to unambiguously get the length in bytes, then converted if
necessary to item values.
-rw-r--r-- | gr-blocks/lib/message_debug_impl.cc | 2 | ||||
-rw-r--r-- | gr-blocks/lib/pdu_to_tagged_stream_impl.cc | 3 | ||||
-rw-r--r-- | gr-blocks/lib/socket_pdu_impl.cc | 4 | ||||
-rw-r--r-- | gr-blocks/lib/tcp_connection.cc | 2 |
4 files changed, 6 insertions, 5 deletions
diff --git a/gr-blocks/lib/message_debug_impl.cc b/gr-blocks/lib/message_debug_impl.cc index 620ca1eb42..8bab788261 100644 --- a/gr-blocks/lib/message_debug_impl.cc +++ b/gr-blocks/lib/message_debug_impl.cc @@ -61,7 +61,7 @@ namespace gr { pmt::pmt_t vector = pmt::cdr(pdu); std::cout << "* MESSAGE DEBUG PRINT PDU VERBOSE *\n"; pmt::print(meta); - size_t len = pmt::length(vector); + size_t len = pmt::blob_length(vector); std::cout << "pdu_length = " << len << std::endl; std::cout << "contents = " << std::endl; size_t offset(0); diff --git a/gr-blocks/lib/pdu_to_tagged_stream_impl.cc b/gr-blocks/lib/pdu_to_tagged_stream_impl.cc index 3a2b50efe1..aec5d335c4 100644 --- a/gr-blocks/lib/pdu_to_tagged_stream_impl.cc +++ b/gr-blocks/lib/pdu_to_tagged_stream_impl.cc @@ -65,7 +65,8 @@ namespace gr { d_curr_meta = pmt::car(msg); d_curr_vect = pmt::cdr(msg); - d_curr_len = pmt::length(d_curr_vect); + // do not assume the length of PMT is in items (e.g.: from socket_pdu) + d_curr_len = pmt::blob_length(d_curr_vect)/d_itemsize; } return d_curr_len; diff --git a/gr-blocks/lib/socket_pdu_impl.cc b/gr-blocks/lib/socket_pdu_impl.cc index 7f7abd50be..cc45557bca 100644 --- a/gr-blocks/lib/socket_pdu_impl.cc +++ b/gr-blocks/lib/socket_pdu_impl.cc @@ -196,7 +196,7 @@ namespace gr { socket_pdu_impl::tcp_client_send(pmt::pmt_t msg) { pmt::pmt_t vector = pmt::cdr(msg); - size_t len = pmt::length(vector); + size_t len = pmt::blob_length(vector); size_t offset = 0; std::vector<char> txbuf(std::min(len, d_rxbuf.size())); while (offset < len) { @@ -214,7 +214,7 @@ namespace gr { return; pmt::pmt_t vector = pmt::cdr(msg); - size_t len = pmt::length(vector); + size_t len = pmt::blob_length(vector); size_t offset = 0; std::vector<char> txbuf(std::min(len, d_rxbuf.size())); while (offset < len) { diff --git a/gr-blocks/lib/tcp_connection.cc b/gr-blocks/lib/tcp_connection.cc index 27bdf6a57d..3b0afa13fc 100644 --- a/gr-blocks/lib/tcp_connection.cc +++ b/gr-blocks/lib/tcp_connection.cc @@ -53,7 +53,7 @@ namespace gr { void tcp_connection::send(pmt::pmt_t vector) { - size_t len = pmt::length(vector); + size_t len = pmt::blob_length(vector); size_t offset = 0; std::vector<char> txbuf(std::min(len, d_buf.size())); while (offset < len) { |