[PATCH] TOOLS: bsefextract: don't segfault if input file is empty



Signed-off-by: Stefan Westerfeld <stefan space twc de>
---
 tools/bsefextract.cc | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/tools/bsefextract.cc b/tools/bsefextract.cc
index 501698b..08cf18d 100644
--- a/tools/bsefextract.cc
+++ b/tools/bsefextract.cc
@@ -77,6 +77,17 @@ class Signal
     return true;
   }
 
+  /* empty signal? */
+  bool empty()
+  {
+    if (m_length < m_n_channels)
+      {
+        assert (m_length == 0);
+        return true;
+      }
+    return false;
+  }
+
 public:
   Signal (GslDataHandle *data_handle) :
     m_data_handle (data_handle)
@@ -102,7 +113,7 @@ public:
     if (options.cut_zeros_head)
       {
        /* cut_zeros head */
-       while (head_is_silent() && m_length > (GslLong) m_n_channels)
+       while (!empty() && head_is_silent())
          {
            m_offset += m_n_channels;
            m_length -= m_n_channels;
@@ -111,7 +122,7 @@ public:
     if (options.cut_zeros_tail)
       {
        /* cut_zeros tail */
-       while (tail_is_silent() && m_length > (GslLong) m_n_channels)
+       while (!empty() && tail_is_silent())
          {
            m_length -= m_n_channels;
          }
-- 
2.7.4



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]