diff options
author | Thomas Habets <thomas@habets.se> | 2020-01-20 14:53:14 +0000 |
---|---|---|
committer | mormj <34754695+mormj@users.noreply.github.com> | 2020-01-20 21:39:42 -0500 |
commit | f9ccbe9f6f9f5994574db3e5f84baad7b3af7037 (patch) | |
tree | ff103515ecf55e3bace96853b3108fa1d2ce7887 | |
parent | 4fd83cd879cc966c60b185cf16793c398a516d0d (diff) |
blocks/tagged_file_sink: Add const and enum type safety
Found by coverity. CID 1043276
-rw-r--r-- | gr-blocks/lib/tagged_file_sink_impl.cc | 19 | ||||
-rw-r--r-- | gr-blocks/lib/tagged_file_sink_impl.h | 8 |
2 files changed, 14 insertions, 13 deletions
diff --git a/gr-blocks/lib/tagged_file_sink_impl.cc b/gr-blocks/lib/tagged_file_sink_impl.cc index 5b53bd1f74..c80a80df3f 100644 --- a/gr-blocks/lib/tagged_file_sink_impl.cc +++ b/gr-blocks/lib/tagged_file_sink_impl.cc @@ -63,12 +63,13 @@ tagged_file_sink_impl::tagged_file_sink_impl(size_t itemsize, double samp_rate) io_signature::make(1, 1, itemsize), io_signature::make(0, 0, 0)), d_itemsize(itemsize), + d_sample_rate(samp_rate), + d_state(state_t::NOT_IN_BURST), + d_handle(nullptr), d_n(0), - d_sample_rate(samp_rate) + d_last_N(0), + d_timeval(0) { - d_state = NOT_IN_BURST; - d_last_N = 0; - d_timeval = 0; } tagged_file_sink_impl::~tagged_file_sink_impl() {} @@ -107,7 +108,7 @@ int tagged_file_sink_impl::work(int noutput_items, int idx = 0, idx_stop = 0; while (idx < noutput_items) { - if (d_state == NOT_IN_BURST) { + if (d_state == state_t::NOT_IN_BURST) { while (vitr != all_tags.end()) { if ((pmt::eqv((*vitr).key, bkey)) && pmt::is_true((*vitr).value)) { @@ -177,13 +178,13 @@ int tagged_file_sink_impl::work(int noutput_items, // std::cout << "Created new file: " << filename.str() << std::endl; - d_state = IN_BURST; + d_state = state_t::IN_BURST; break; } vitr++; } - if (d_state == NOT_IN_BURST) + if (d_state == state_t::NOT_IN_BURST) return noutput_items; } else { // In burst while (vitr != all_tags.end()) { @@ -202,7 +203,7 @@ int tagged_file_sink_impl::work(int noutput_items, } } idx = idx_stop; - d_state = NOT_IN_BURST; + d_state = state_t::NOT_IN_BURST; vitr++; fclose(d_handle); break; @@ -210,7 +211,7 @@ int tagged_file_sink_impl::work(int noutput_items, vitr++; } } - if (d_state == IN_BURST) { + if (d_state == state_t::IN_BURST) { int count = fwrite( &inbuf[d_itemsize * idx], d_itemsize, noutput_items - idx, d_handle); if (count == 0) { diff --git a/gr-blocks/lib/tagged_file_sink_impl.h b/gr-blocks/lib/tagged_file_sink_impl.h index 836f46dbca..998b8d20fd 100644 --- a/gr-blocks/lib/tagged_file_sink_impl.h +++ b/gr-blocks/lib/tagged_file_sink_impl.h @@ -32,13 +32,13 @@ namespace blocks { class tagged_file_sink_impl : public tagged_file_sink { private: - enum { NOT_IN_BURST = 0, IN_BURST }; + enum class state_t { NOT_IN_BURST = 0, IN_BURST }; - size_t d_itemsize; - int d_state; + const size_t d_itemsize; + const double d_sample_rate; + state_t d_state; FILE* d_handle; int d_n; - double d_sample_rate; uint64_t d_last_N; double d_timeval; |