mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2024-11-30 08:24:11 +01:00
Ground/UAVObjectField: Explicitly handle case of bad enum values to avoid crashes. Still shouldn't occur.
git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@1703 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
parent
862e35def1
commit
7a8424e98e
@ -27,6 +27,7 @@
|
||||
*/
|
||||
#include "uavobjectfield.h"
|
||||
#include <QtEndian>
|
||||
#include <QDebug>
|
||||
|
||||
UAVObjectField::UAVObjectField(const QString& name, const QString& units, FieldType type, quint32 numElements, const QStringList& options)
|
||||
{
|
||||
@ -444,6 +445,11 @@ QVariant UAVObjectField::getValue(quint32 index)
|
||||
{
|
||||
quint8 tmpenum;
|
||||
memcpy(&tmpenum, &data[offset + numBytesPerElement*index], numBytesPerElement);
|
||||
// Q_ASSERT((tmpenum < options.length()) && (tmpenum >= 0)); // catch bad enum settings
|
||||
if(tmpenum >= options.length()) {
|
||||
qDebug() << "Invalid value for" << name;
|
||||
return QVariant( QString("Bad Value") );
|
||||
}
|
||||
return QVariant( options[tmpenum] );
|
||||
break;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user