diff --git a/reader.go b/reader.go index b5b3d6f..29df08c 100644 --- a/reader.go +++ b/reader.go @@ -740,16 +740,16 @@ func (d *decoder) parseFitField(dm *defmsg, dfield fieldDef, fieldv reflect.Valu f64 := math.Float64frombits(bits) fieldv.SetFloat(f64) case types.BaseString: - for j := 0; j < dsize; j++ { + var j int + + for j = 0; j < dsize; j++ { if d.tmp[j] == 0x00 { - if j > 0 { - fieldv.SetString(string(d.tmp[:j])) - } break } - if j == dsize-1 { - fieldv.SetString(string(d.tmp[:j])) - } + } + + if j > 0 { + fieldv.SetString(string(d.tmp[:j])) } default: return fmt.Errorf( diff --git a/reader_files_test.go b/reader_files_test.go index 4c7d2ee..8318496 100644 --- a/reader_files_test.go +++ b/reader_files_test.go @@ -300,4 +300,15 @@ var decodeTestFiles = [...]struct { true, "Contains developer data fields", }, + { + "misc", + "unterminated-strings.fit", + "https://github.com/tormoder/fit/pull/84", + false, + 11593656398538188064, + true, + tdoNone, + true, + "Contains string fields without NULL terminator", + }, } diff --git a/testdata/misc/unterminated-strings.fit b/testdata/misc/unterminated-strings.fit new file mode 100644 index 0000000..12ac522 Binary files /dev/null and b/testdata/misc/unterminated-strings.fit differ diff --git a/testdata/misc/unterminated-strings.fit.golden.gz b/testdata/misc/unterminated-strings.fit.golden.gz new file mode 100644 index 0000000..496130f Binary files /dev/null and b/testdata/misc/unterminated-strings.fit.golden.gz differ