Skip to content

Commit

Permalink
fix generic string to use size up to first 0
Browse files Browse the repository at this point in the history
  • Loading branch information
roznet committed Jan 10, 2021
1 parent 5f1aa09 commit 32f23bd
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
20 changes: 18 additions & 2 deletions Sources/FitFileParserObjc/FitInterpretMesg.m
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,28 @@ -(BOOL)interpret:(nonnull FIT_CONVERT_STATE*)state{

if( base_type_num==7){ // String
const char * start = (const char*)mesg_buf;
NSUInteger use_size = 0;
bool no_zero = true;
for (field_size = 0; field_size < state->convert_table[state->mesg_index].fields[field].size; field_size += base_type_size){
if( *mesg_buf == 0 ){
no_zero = false;
}
if( no_zero ){
use_size += base_type_size;
}
mesg_buf += base_type_size;
}

_fields.string_values[ _fields.string_count ] = (FIT_UINT32)self.dynamicStrings.count;
_fields.string_types[ _fields.string_count ] = FIT_TYPE_DYNAMIC_STRING;
NSString * fullString = [[NSString alloc] initWithBytes:start
length:state->convert_table[state->mesg_index].fields[field].size
length:use_size
encoding:NSUTF8StringEncoding];
[self.dynamicStringsStore addObject:fullString];
if( fullString ){
[self.dynamicStringsStore addObject:fullString];
}else{
[self.dynamicStringsStore addObject:@""];
}
added_string = true;
}else{
BOOL in_array = false;
Expand Down
4 changes: 2 additions & 2 deletions Tests/FitFileParserSwiftTests/FitFileParserSwiftTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@ final class FitFileParserSwiftTests: XCTestCase {
// skip empty string, not interpreted the same
continue
}
XCTAssertNotNil(generic_message.interpretedField(key: fast_key), fast_key)
XCTAssertNotNil(generic_message.interpretedField(key: fast_key), "\(message.messageType.name()).\(fast_key): missing")
// Know fields where array skipped in fast mode
if generic_message.messageType == .developer_data_id && fast_key == "application_id" {
continue
}
if let generic_value = generic_message.interpretedField(key: fast_key){
XCTAssertEqual(generic_value, fast_value)
XCTAssertEqual(generic_value, fast_value, "\(message.messageType.name()).\(fast_key): generic and fast match")
}
}
generic_idx+=1
Expand Down

0 comments on commit 32f23bd

Please sign in to comment.