@@ -452,7 +452,7 @@ struct field_desc {
452452 { \
453453 char fmtbuf[FMTSIZE]; \
454454 if (strcmp(#type, base_type_info[base_type].type_name)) \
455- fprintf(stderr , "%s: %s should be %s\n", #name, #type, base_type_info[base_type].type_name); \
455+ WARNING(g->base.context , "%s: %s should be %s\n", #name, #type, base_type_info[base_type].type_name); \
456456 type val = type##_VALUE(g, p); \
457457 if (val == type##_INVAL) return; \
458458 type##_FORMAT(val, fmtbuf); \
@@ -1499,29 +1499,25 @@ traverse_data(struct garmin_parser_t *garmin)
14991499 memset (& garmin -> record_data , 0 , sizeof (garmin -> record_data ));
15001500 memset (garmin -> type_desc , 0 , sizeof (garmin -> type_desc ));
15011501
1502- // The data starts with our filename fingerprint. Skip it.
1503- if (len < FIT_NAME_SIZE )
1504- return DC_STATUS_IO ;
1505-
1506- DEBUG (garmin -> base .context , "file %.*s" , FIT_NAME_SIZE , data );
1507-
1508- data += FIT_NAME_SIZE ;
1509- len -= FIT_NAME_SIZE ;
1510-
15111502 // The FIT header
1512- if (len < 12 )
1503+ if (len < 12 ) {
1504+ ERROR (garmin -> base .context , " file too short for FIT header" );
1505+
15131506 return DC_STATUS_IO ;
1507+ }
15141508
15151509 hdrsize = data [0 ];
15161510 protocol = data [1 ];
15171511 profile = array_uint16_le (data + 2 ); // these two fields are always little endian
15181512 datasize = array_uint32_le (data + 4 );
15191513 if (memcmp (data + 8 , ".FIT" , 4 )) {
1520- DEBUG (garmin -> base .context , " missing .FIT marker" );
1514+ ERROR (garmin -> base .context , " missing .FIT marker" );
1515+
15211516 return DC_STATUS_IO ;
15221517 }
15231518 if (hdrsize < 12 || datasize > len || datasize + hdrsize + 2 > len ) {
1524- DEBUG (garmin -> base .context , " inconsistent size information hdrsize %d datasize %d len %d" , hdrsize , datasize , len );
1519+ ERROR (garmin -> base .context , " inconsistent size information hdrsize %d datasize %d len %d" , hdrsize , datasize , len );
1520+
15251521 return DC_STATUS_IO ;
15261522 }
15271523 garmin -> dive .protocol = protocol ;
@@ -1563,8 +1559,11 @@ traverse_data(struct garmin_parser_t *garmin)
15631559 DEBUG (garmin -> base .context , "Regular record for type %d" , record );
15641560 len = traverse_regular (garmin , data , datasize , record , & time );
15651561 }
1566- if (len <= 0 || len > datasize )
1562+ if (len <= 0 || len > datasize ) {
1563+ ERROR (garmin -> base .context , " traverse failed" );
1564+
15671565 return DC_STATUS_IO ;
1566+ }
15681567 data += len ;
15691568 datasize -= len ;
15701569
0 commit comments