mirror of
https://github.com/tumic0/GPXSee.git
synced 2025-01-31 00:55:13 +01:00
Added struct size padding asserts to FIT parser
This commit is contained in:
parent
66ce91c237
commit
584245785e
11
src/assert.h
Normal file
11
src/assert.h
Normal file
@ -0,0 +1,11 @@
|
||||
#ifndef ASSERT_H
|
||||
#define ASSERT_H
|
||||
|
||||
template<bool> struct CompileTimeAssert;
|
||||
template<> struct CompileTimeAssert <true> {};
|
||||
|
||||
#define STATIC_ASSERT(e) \
|
||||
(CompileTimeAssert <(e) != 0>())
|
||||
|
||||
#endif // ASSERT_H
|
||||
|
@ -1,5 +1,6 @@
|
||||
#include <cstring>
|
||||
#include <QtEndian>
|
||||
#include "assert.h"
|
||||
#include "fitparser.h"
|
||||
|
||||
|
||||
@ -122,6 +123,7 @@ bool FITParser::parseDefinitionMessage(quint8 header)
|
||||
// definition records
|
||||
def->fields = new Field[def->numFields];
|
||||
for (i = 0; i < def->numFields; i++) {
|
||||
STATIC_ASSERT(sizeof(def->fields[i]) == 3);
|
||||
if (!readData((char*)&(def->fields[i]), sizeof(def->fields[i])))
|
||||
return false;
|
||||
_len -= sizeof(def->fields[i]);
|
||||
@ -134,6 +136,7 @@ bool FITParser::parseDefinitionMessage(quint8 header)
|
||||
|
||||
def->devFields = new Field[def->numDevFields];
|
||||
for (i = 0; i < def->numDevFields; i++) {
|
||||
STATIC_ASSERT(sizeof(def->devFields[i]) == 3);
|
||||
if (!readData((char*)&(def->devFields[i]),
|
||||
sizeof(def->devFields[i])))
|
||||
return false;
|
||||
@ -302,6 +305,7 @@ bool FITParser::parseHeader()
|
||||
quint16 crc;
|
||||
qint64 len;
|
||||
|
||||
STATIC_ASSERT(sizeof(hdr) == 12);
|
||||
len = _device->read((char*)&hdr, sizeof(hdr));
|
||||
if (len < 0) {
|
||||
_errorString = "I/O error";
|
||||
|
Loading…
x
Reference in New Issue
Block a user