added missing check for invalid position in *DataField::read() and require remainder to be at least 1 byte long, formatting
This commit is contained in:
@@ -274,10 +274,11 @@ result_t SingleDataField::create(const string id, const unsigned char length,
|
|||||||
for (unsigned int i = 0; i < sizeof(dayNames) / sizeof(dayNames[0]); i++)
|
for (unsigned int i = 0; i < sizeof(dayNames) / sizeof(dayNames[0]); i++)
|
||||||
values[numType->getMinValue() + i] = dayNames[i];
|
values[numType->getMinValue() + i] = dayNames[i];
|
||||||
}
|
}
|
||||||
if (values.empty()) {
|
|
||||||
result_t result = numType->derive(divisor, bitCount, numType);
|
result_t result = numType->derive(divisor, bitCount, numType);
|
||||||
if (result!=RESULT_OK)
|
if (result!=RESULT_OK) {
|
||||||
return result;
|
return result;
|
||||||
|
}
|
||||||
|
if (values.empty()) {
|
||||||
returnField = new SingleDataField(name, comment, unit, numType, partType, byteCount);
|
returnField = new SingleDataField(name, comment, unit, numType, partType, byteCount);
|
||||||
return RESULT_OK;
|
return RESULT_OK;
|
||||||
}
|
}
|
||||||
@@ -329,11 +330,11 @@ result_t SingleDataField::read(const PartType partType,
|
|||||||
default:
|
default:
|
||||||
return RESULT_ERR_INVALID_PART;
|
return RESULT_ERR_INVALID_PART;
|
||||||
}
|
}
|
||||||
if (isIgnored() || (fieldName != NULL && (m_name != fieldName || fieldIndex > 0))) {
|
|
||||||
bool remainder = m_length==REMAIN_LEN && m_dataType->isAdjustableLength();
|
bool remainder = m_length==REMAIN_LEN && m_dataType->isAdjustableLength();
|
||||||
if (!remainder && offset + m_length > data.size()) {
|
if (offset + (remainder?1:m_length) > data.size()) {
|
||||||
return RESULT_ERR_INVALID_POS;
|
return RESULT_ERR_INVALID_POS;
|
||||||
}
|
}
|
||||||
|
if (isIgnored() || (fieldName != NULL && (m_name != fieldName || fieldIndex > 0))) {
|
||||||
return RESULT_EMPTY;
|
return RESULT_EMPTY;
|
||||||
}
|
}
|
||||||
return m_dataType->readRawValue(data, offset, m_length, output);
|
return m_dataType->readRawValue(data, offset, m_length, output);
|
||||||
@@ -358,11 +359,11 @@ result_t SingleDataField::read(const PartType partType,
|
|||||||
default:
|
default:
|
||||||
return RESULT_ERR_INVALID_PART;
|
return RESULT_ERR_INVALID_PART;
|
||||||
}
|
}
|
||||||
if (isIgnored() || (fieldName != NULL && (m_name != fieldName || fieldIndex > 0))) {
|
|
||||||
bool remainder = m_length==REMAIN_LEN && m_dataType->isAdjustableLength();
|
bool remainder = m_length==REMAIN_LEN && m_dataType->isAdjustableLength();
|
||||||
if (!remainder && offset + m_length > data.size()) {
|
if (offset + (remainder?1:m_length) > data.size()) {
|
||||||
return RESULT_ERR_INVALID_POS;
|
return RESULT_ERR_INVALID_POS;
|
||||||
}
|
}
|
||||||
|
if (isIgnored() || (fieldName != NULL && (m_name != fieldName || fieldIndex > 0))) {
|
||||||
return RESULT_EMPTY;
|
return RESULT_EMPTY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+3
-3
@@ -294,11 +294,11 @@ public:
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get whether this field uses a full byte offset.
|
* Get whether this field uses a full byte offset.
|
||||||
* @param after @p true to check after consuming the bits, false to check before.
|
* @param after @p true to check after consuming the bits, @p false to check before.
|
||||||
* @return true if this field uses a full byte offset, false if this field
|
* @return @p true if this field uses a full byte offset, @p false if this field
|
||||||
* only consumes a part of a byte and a subsequent field may re-use the same offset.
|
* only consumes a part of a byte and a subsequent field may re-use the same offset.
|
||||||
*/
|
*/
|
||||||
virtual bool hasFullByteOffset(bool after);
|
bool hasFullByteOffset(bool after);
|
||||||
|
|
||||||
// @copydoc
|
// @copydoc
|
||||||
virtual void dump(ostream& output);
|
virtual void dump(ostream& output);
|
||||||
|
|||||||
Reference in New Issue
Block a user