From 458ff8d6278b2bc62ad5f4cb7fbcd4fcaab66d9f Mon Sep 17 00:00:00 2001 From: Thomas Habets <thomas@habets.se> Date: Mon, 20 Jan 2020 15:12:06 +0000 Subject: blocks/file_source: Check for fseek() failing Found by coverity. CID: * 1395913 * 1395940 --- gr-blocks/lib/file_source_impl.cc | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'gr-blocks/lib/file_source_impl.cc') diff --git a/gr-blocks/lib/file_source_impl.cc b/gr-blocks/lib/file_source_impl.cc index ee8f08d980..cfb1960d2a 100644 --- a/gr-blocks/lib/file_source_impl.cc +++ b/gr-blocks/lib/file_source_impl.cc @@ -162,7 +162,9 @@ void file_source_impl::open(const char* filename, if (d_seekable) { // Check to ensure the file will be consumed according to item size - GR_FSEEK(d_new_fp, 0, SEEK_END); + if (GR_FSEEK(d_new_fp, 0, SEEK_END) == -1) { + throw std::runtime_error("can't fseek()"); + } file_size = GR_FTELL(d_new_fp); // Make sure there will be at least one item available @@ -198,7 +200,9 @@ void file_source_impl::open(const char* filename, // Rewind to start offset if (d_seekable) { - GR_FSEEK(d_new_fp, start_offset_items * d_itemsize, SEEK_SET); + if (GR_FSEEK(d_new_fp, start_offset_items * d_itemsize, SEEK_SET) == -1) { + throw std::runtime_error("can't fseek()"); + } } d_updated = true; @@ -281,7 +285,9 @@ int file_source_impl::work(int noutput_items, // Repeat: rewind and request tag if (d_repeat && d_seekable) { - GR_FSEEK(d_fp, d_start_offset_items * d_itemsize, SEEK_SET); + if (GR_FSEEK(d_fp, d_start_offset_items * d_itemsize, SEEK_SET) == -1) { + throw std::runtime_error("can't fseek()"); + } d_items_remaining = d_length_items; if (d_add_begin_tag != pmt::PMT_NIL) { d_file_begin = true; -- cgit v1.2.3