diff options
author | Marcus Müller <mueller@kit.edu> | 2018-07-18 18:02:45 +0200 |
---|---|---|
committer | Marcus Müller <marcus@hostalia.de> | 2018-08-23 22:18:26 +0200 |
commit | 94c7a31ab80555c86d2207eb44c6c7fa6e59b9d5 (patch) | |
tree | 3d22cdf0973bcab78470db84227a0a6eb04a074f /gnuradio-runtime/lib/pmt | |
parent | 75b4ae3d2a64cbf9b3dc473f5821aaf1997b4a6c (diff) |
Fixed out-of-bound vector acces in PMT (pre-C++11 version)
adresses cases where initialization of uvec happened with empty
`std::vector`, as well as when getting the address of the first element
of an empty uvec, lead to undefined behaviour through doing `vec[0]` for
empty `vec`.
This commit, unlike the similar commit of the same message, uses `NULL`
in case of `nullptr` (maint-3.7 doesn't require C++11).
Diffstat (limited to 'gnuradio-runtime/lib/pmt')
-rw-r--r-- | gnuradio-runtime/lib/pmt/unv_template.cc.t | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/gnuradio-runtime/lib/pmt/unv_template.cc.t b/gnuradio-runtime/lib/pmt/unv_template.cc.t index c9402de19d..62b810acab 100644 --- a/gnuradio-runtime/lib/pmt/unv_template.cc.t +++ b/gnuradio-runtime/lib/pmt/unv_template.cc.t @@ -21,7 +21,8 @@ pmt_@TAG@vector::pmt_@TAG@vector(size_t k, @TYPE@ fill) pmt_@TAG@vector::pmt_@TAG@vector(size_t k, const @TYPE@ *data) : d_v(k) { - memcpy( &d_v[0], data, k * sizeof(@TYPE@) ); + if(k) + memcpy( &d_v[0], data, k * sizeof(@TYPE@) ); } @TYPE@ @@ -44,28 +45,28 @@ const @TYPE@ * pmt_@TAG@vector::elements(size_t &len) { len = length(); - return &d_v[0]; + return len ? &d_v[0] : NULL; } @TYPE@ * pmt_@TAG@vector::writable_elements(size_t &len) { len = length(); - return &d_v[0]; + return len ? &d_v[0] : NULL; } const void* pmt_@TAG@vector::uniform_elements(size_t &len) { len = length() * sizeof(@TYPE@); - return &d_v[0]; + return len ? &d_v[0] : NULL; } void* pmt_@TAG@vector::uniform_writable_elements(size_t &len) { len = length() * sizeof(@TYPE@); - return &d_v[0]; + return len ? (&d_v[0]) : NULL; } bool @@ -89,8 +90,10 @@ init_@TAG@vector(size_t k, const @TYPE@ *data) pmt_t init_@TAG@vector(size_t k, const std::vector< @TYPE@ > &data) { - - return pmt_t(new pmt_@TAG@vector(k, &data[0])); + if(k) { + return pmt_t(new pmt_@TAG@vector(k, &data[0])); + } + return pmt_t(new pmt_@TAG@vector(k, static_cast< @TYPE@ >(0))); // fills an empty vector with 0 } @TYPE@ |