From bc4d7adce79035bd1c4e7c105f252582c20adfce Mon Sep 17 00:00:00 2001 From: Jason Gerecke Date: Fri, 20 Apr 2018 21:52:57 -0700 Subject: [PATCH] FileSourceGui: Prevent potential integer overflow in updateWithStreamTime UBSan reports the following error when replaying an IQ stream: ./plugins/samplesource/filesource/filesourcegui.cpp:331:29: runtime error: signed integer overflow: 2704064 * 1000 cannot be represented in type 'int' By rearranging the calculation, we can be sure that the calculation never overflows. --- plugins/samplesource/filesource/filesourcegui.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/samplesource/filesource/filesourcegui.cpp b/plugins/samplesource/filesource/filesourcegui.cpp index d679ae889..c74a6270f 100644 --- a/plugins/samplesource/filesource/filesourcegui.cpp +++ b/plugins/samplesource/filesource/filesourcegui.cpp @@ -328,8 +328,8 @@ void FileSourceGui::updateWithStreamTime() int t_msec = 0; if (m_sampleRate > 0){ - t_msec = ((m_samplesCount * 1000) / m_sampleRate) % 1000; t_sec = m_samplesCount / m_sampleRate; + t_msec = (m_samplesCount - (t_sec * m_sampleRate)) * 1000 / m_sampleRate; } QTime t(0, 0, 0, 0);