提交 c3b50c3f 编写于 作者: 丁劲犇's avatar 丁劲犇 😸

解决内存越界导致的崩溃

上级 f8b6233e
......@@ -66,7 +66,7 @@ void DialogPlots::deal_package(QByteArray package)
return;
const subject_package_header * pheader = (const subject_package_header *)
package.constData();
package.constData();
if (m_plot_idxes.contains(pheader->subject_id)==false)
return;
......@@ -155,7 +155,7 @@ QVector<double> DialogPlots::flush_data(QByteArray package)
return vec_res;
const subject_package_header * pheader = (const subject_package_header *)
package.constData();
package.constData();
if (m_plot_idxes.contains(pheader->subject_id)==false)
return vec_res;
......@@ -173,83 +173,83 @@ QVector<double> DialogPlots::flush_data(QByteArray package)
{
case 0:
pts = pheader->data_length/sizeof(quint8)/channels;
{
const quint8 * ptrRaw = (const quint8 *) rawdata;
for (int i=0;i<pts;++i)
vec_res<<ptrRaw[i];
}
{
const quint8 * ptrRaw = (const quint8 *) rawdata;
for (int i=0;i<pts;++i)
vec_res<<ptrRaw[i];
}
break;
case 1:
pts = pheader->data_length/sizeof(qint8)/channels;
{
const qint8 * ptrRaw = (const qint8 *) rawdata;
for (int i=0;i<pts;++i)
vec_res<<ptrRaw[i];
}
{
const qint8 * ptrRaw = (const qint8 *) rawdata;
for (int i=0;i<pts;++i)
vec_res<<ptrRaw[i];
}
break;
case 2:
pts = pheader->data_length/sizeof(quint16)/channels;
{
const quint16 * ptrRaw = (const quint16 *) rawdata;
for (int i=0;i<pts;++i)
vec_res<<ptrRaw[i];
}
{
const quint16 * ptrRaw = (const quint16 *) rawdata;
for (int i=0;i<pts;++i)
vec_res<<ptrRaw[i];
}
break;
case 3:
pts = pheader->data_length/sizeof(qint16)/channels;
{
const qint16 * ptrRaw = (const qint16 *) rawdata;
for (int i=0;i<pts;++i)
vec_res<<ptrRaw[i];
}
{
const qint16 * ptrRaw = (const qint16 *) rawdata;
for (int i=0;i<pts;++i)
vec_res<<ptrRaw[i];
}
break;
case 4:
pts = pheader->data_length/sizeof(quint32)/channels;
{
const quint32 * ptrRaw = (const quint32 *) rawdata;
for (int i=0;i<pts;++i)
vec_res<<ptrRaw[i];
}
{
const quint32 * ptrRaw = (const quint32 *) rawdata;
for (int i=0;i<pts;++i)
vec_res<<ptrRaw[i];
}
break;
case 5:
pts = pheader->data_length/sizeof(qint32)/channels;
{
const qint32 * ptrRaw = (const qint32 *) rawdata;
for (int i=0;i<pts;++i)
vec_res<<ptrRaw[i];
}
{
const qint32 * ptrRaw = (const qint32 *) rawdata;
for (int i=0;i<pts;++i)
vec_res<<ptrRaw[i];
}
break;
case 6:
pts = pheader->data_length/sizeof(quint64)/channels;
{
const quint64 * ptrRaw = (const quint64 *) rawdata;
for (int i=0;i<pts;++i)
vec_res<<ptrRaw[i];
}
{
const quint64 * ptrRaw = (const quint64 *) rawdata;
for (int i=0;i<pts;++i)
vec_res<<ptrRaw[i];
}
break;
case 7:
pts = pheader->data_length/sizeof(qint64)/channels;
{
const qint64 * ptrRaw = (const qint64 *) rawdata;
for (int i=0;i<pts;++i)
vec_res<<ptrRaw[i];
}
{
const qint64 * ptrRaw = (const qint64 *) rawdata;
for (int i=0;i<pts;++i)
vec_res<<ptrRaw[i];
}
break;
case 8:
pts = pheader->data_length/sizeof(float)/channels;
{
const float * ptrRaw = (const float *) rawdata;
for (int i=0;i<pts;++i)
vec_res<<ptrRaw[i];
}
{
const float * ptrRaw = (const float *) rawdata;
for (int i=0;i<pts;++i)
vec_res<<ptrRaw[i];
}
break;
case 9:
pts = pheader->data_length/sizeof(double)/channels;
{
const double * ptrRaw = (const double *) rawdata;
for (int i=0;i<pts;++i)
vec_res<<ptrRaw[i];
}
{
const double * ptrRaw = (const double *) rawdata;
for (int i=0;i<pts;++i)
vec_res<<ptrRaw[i];
}
break;
default:
break;
......@@ -301,7 +301,10 @@ void DialogPlots::on_pushButton_reset_clicked()
if (min_y < new_min_y) new_min_y = min_y,needup_y=true;
if (min_y > new_min_y * 1.2) new_min_y = min_y,needup_y=true;
if (max_x >=1e9 || max_x <-1e9 || max_y >1e9 ||max_y < -1e9 || max_x - min_x <1e-8)
needup_x = false,needup_y = false;
if (min_y >=1e9 || min_y <-1e9 || min_x >1e9 ||min_x < -1e9|| max_y - min_y <1e-8)
needup_x = false,needup_y = false;
if (needup_x==true)
ax->setRange(new_min_x,new_max_x);
......@@ -367,7 +370,7 @@ void DialogPlots::timerEvent(QTimerEvent *event)
for (QList<QVector<double> >::iterator pit = avgList.begin();pit!=avgList.end();++pit)
{
for (int i=0;i<pts;++i)
fdata[i] += pit->at(i)/avgsz;
fdata[i] += pit->at(i)/(avgsz+1e-14);
}
double max_x = 0, max_y = fdata[0];
......@@ -382,7 +385,7 @@ void DialogPlots::timerEvent(QTimerEvent *event)
{
SpectroWidget * ws = m_chat_spec[subid];
QVector<QPointF> vec_points;
for (int i=0;i<pts;i+=step)
for (int i=0;i<pts/channels;i+=step)
{
double x,y;
if (channels==1)
......@@ -397,26 +400,30 @@ void DialogPlots::timerEvent(QTimerEvent *event)
if (y<min_y) min_y = y;
}
serials->replace(vec_points);
if (ws)
if (!(max_x >=1e9 || max_x <-1e9 || max_y >1e9 ||max_y < -1e9 || max_x - min_x <1e-8)||
(min_y >=1e9 || min_y <-1e9 || min_x >1e9 ||min_x < -1e9|| max_y - min_y <1e-8))
{
QChart * ca = m_chars[subid];
QValueAxis * axx = m_char_axis_x[subid];
QValueAxis * axy = m_char_axis_y[subid];
double dmin = axx->min();
double dmax = axx->max();
QRectF r = ca->plotArea();
ws->setMinMaxRange(axy->min(),axy->max());
ws->append_data(vec_tmp,
r.left(),
r.right(),
dmin,
dmax
);
serials->replace(vec_points);
if (ws)
{
QChart * ca = m_chars[subid];
QValueAxis * axx = m_char_axis_x[subid];
QValueAxis * axy = m_char_axis_y[subid];
double dmin = axx->min();
double dmax = axx->max();
QRectF r = ca->plotArea();
ws->setMinMaxRange(axy->min(),axy->max());
ws->append_data(vec_tmp,
r.left(),
r.right(),
dmin,
dmax
);
}
}
......@@ -438,8 +445,9 @@ void DialogPlots::timerEvent(QTimerEvent *event)
if (y<min_y) min_y = y;
}
serials->replace(lstpts);
if (!(max_x >=1e9 || max_x <-1e9 || max_y >1e9 ||max_y < -1e9 || max_x - min_x <1e-8)||
(min_y >=1e9 || min_y <-1e9 || min_x >1e9 ||min_x < -1e9|| max_y - min_y <1e-8))
serials->replace(lstpts);
}
//QChart *chart = m_chars[subid];
......@@ -465,6 +473,10 @@ void DialogPlots::timerEvent(QTimerEvent *event)
if (min_y < new_min_y) new_min_y = min_y,needup_y=true;
if (min_y > new_min_y * 1.2) new_min_y = min_y,needup_y=true;
if (max_x >=1e9 || max_x <-1e9 || max_y >1e9 ||max_y < -1e9 || max_x - min_x <1e-8)
needup_x = false,needup_y = false;
if (min_y >=1e9 || min_y <-1e9 || min_x >1e9 ||min_x < -1e9|| max_y - min_y <1e-8)
needup_x = false,needup_y = false;
if (ui->checkBox_auto_reser->isChecked() || needup_x)
{
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册