From 88d8070db4f4348a11a25c20ea2b8814fec5fa32 Mon Sep 17 00:00:00 2001 From: Jordan Sherer Date: Mon, 25 Nov 2019 20:13:00 -0500 Subject: [PATCH] Fixed segfault in jsc compression code --- jsc.cpp | 19 +++++++++++-------- mainwindow.cpp | 3 +++ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/jsc.cpp b/jsc.cpp index 7283f60..683fc81 100644 --- a/jsc.cpp +++ b/jsc.cpp @@ -112,7 +112,7 @@ QString JSC::decompress(Codeword const& bitvec){ base[7] = base[6] + s*c*c*c*c*c*c; QList bytes; - QList separators; + QList separators; int i = 0; int count = bitvec.count(); @@ -133,22 +133,25 @@ QString JSC::decompress(Codeword const& bitvec){ } } - int start = 0; - while(start < bytes.length()){ - int k = 0; - int j = 0; + quint32 start = 0; + while(start < (quint32)bytes.length()){ + quint32 k = 0; + quint32 j = 0; - while(start + k < bytes.length() && bytes[start + k] >= s){ + while(start + k < (quint32)bytes.length() && bytes[start + k] >= s){ j = j*c + (bytes[start + k] - s); k++; } + if(j >= JSC::size){ + break; + } - if(start + k >= bytes.length()){ + if(start + k >= (quint32)bytes.length()){ break; } j = j*s + bytes[start + k] + base[k]; - if(j >= (int)JSC::size){ + if(j >= JSC::size){ break; } diff --git a/mainwindow.cpp b/mainwindow.cpp index e966e0b..2edba9c 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -1852,6 +1852,9 @@ void MainWindow::initializeDummyData(){ c.setCharFormat(f); #endif + // this causes a segfault! + processDecodedLine("223000 -15 -0.3 1681 B 6t++yk+aJbaE 6 \n"); + ui->extFreeTextMsgEdit->setPlainText("HELLOBRAVE NEW WORLD"); ui->extFreeTextMsgEdit->setCharsSent(6);