schwehr / generic-sensor-format

Sonar Generic Sensor Format (gsf) codec
Other
13 stars 8 forks source link

using sizeof(struct foo) is a bad idea for serialization #47

Open schwehr opened 9 years ago

schwehr commented 9 years ago

The character array needs to be 13 to allow for a trailing \0. However, that bumps the struct size up to 16 causing the gsf write code to write a 16 byte block instead of the original 12.

gsfHeader uses the size of the struct to determine the size of what to write.

schwehr commented 9 years ago

The issue was triggered via https://github.com/schwehr/generic-sensor-format/commit/6426eafe4315f55cc4a3d04886f645ca36a96a70

The original issue: CID 113091 https://scan8.coverity.com/reports.htm#v26674/p11182/fileInstanceId=6388473&defectInstanceId=2398076&mergedDefectId=113091&eventId=2398076-0