kosma / minmea

a lightweight GPS NMEA 0183 parser library in pure C
Do What The F*ck You Want To Public License
755 stars 246 forks source link

parse_gll1 test fails #14

Closed maximevince closed 8 years ago

maximevince commented 8 years ago

When running the test on my Arch Linux machine, w/ GCC 5.3.0, I get following failure:

+++ Running Check test suite... ./tests Running suite(s): minmea 96%: Checks: 30, Failures: 1, Errors: 0 tests.c:584:F:minmea_parse:test_minmea_parse_gll1:0: Assertion '!memcmp(&frame, &expected, sizeof(frame))' failed Makefile:15: recipe for target 'test' failed

However, when looking at the structs frame and expected manually with GDB, them seem to be identical. Not sure yet what's going on.

maximevince commented 8 years ago

struct comparison using memcmp can be tricky in C... Apparently the actual fields are the same, but some padding fields are not:

(gdb) p frame
$6 = {latitude = {value = 37232475, scale = 10000}, longitude = {value = -121583416, scale = 10000}, time = {hours = 16, minutes = 12, seconds = 29, microseconds = 487000}, status = 65 'A', mode = 65 'A'}
(gdb) p expected
$7 = {latitude = {value = 37232475, scale = 10000}, longitude = {value = -121583416, scale = 10000}, time = {hours = 16, minutes = 12, seconds = 29, microseconds = 487000}, status = 65 'A', mode = 65 'A'}

(gdb) x/9x &frame
0x7fffffffdd80: 0x02381f5b      0x00002710      0xf8c0c8c8      0x00002710
0x7fffffffdd90: 0x00000010      0x0000000c      0x0000001d      0x00076e58
0x7fffffffdda0: 0x00004141
(gdb) x/9x &expected
0x7fffffffddb0: 0x02381f5b      0x00002710      0xf8c0c8c8      0x00002710
0x7fffffffddc0: 0x00000010      0x0000000c      0x0000001d      0x00076e58
0x7fffffffddd0: 0x00614141
arturmadrzak commented 8 years ago

As it was mentioned in pull request this is struct padding problem, which is already fixed and recently merged. Thanks for ur contribution.