The following commit has been merged in the master branch:
commit 421ba21d75d4e35fbe50eb6e4f05bd40bb58f6d6
Author: Andrei Zavada <[email protected]>
Date: Sat Apr 20 00:30:47 2013 +0300
catch exceptions from stof when parsing "EDF Annotations"
diff --git a/src/libsigfile/edf.cc b/src/libsigfile/edf.cc
index da07a95..cfa3ee7 100644
--- a/src/libsigfile/edf.cc
+++ b/src/libsigfile/edf.cc
@@ -845,38 +845,44 @@ _extract_embedded_annotations()
size_t alen = AH.samples_per_record * 2;
- for ( size_t r = 0; r < n_data_records; ++r ) {
- char *this_a =
- (char*)_mmapping + header_length
- + r * _total_samples_per_record * 2 // full records
before
- + AH._at; // offset to
our samples
- string abuf (this_a, alen); // NULL-terminated, possibly at
pos <alen
-
- time_t record_start = _start_time + r * data_record_size;
-
- float offset,
- duration;
- const char
- *offset_p = abuf.c_str(),
- *duration_p,
- *tals_p;
- while ( (tals_p = index( offset_p, 21)) ) {
- if ( (duration = 0.,
- (duration_p = index( offset_p, 20))) &&
- duration_p < tals_p ) {
- offset = stof( string (offset_p, duration_p -
offset_p));
- duration = stof( string (duration_p, tals_p -
duration_p));
- } else
- offset = stof( string (offset_p, tals_p -
offset_p));
-
- auto tals = tokens( tals_p, (char)20);
- for ( auto& t : tals )
- common_annotations.emplace_back(
- record_start + offset,
- record_start + offset + duration,
- t,
- SAnnotation::TType::plain);
+ try {
+ for ( size_t r = 0; r < n_data_records; ++r ) {
+ char *this_a =
+ (char*)_mmapping + header_length
+ + r * _total_samples_per_record * 2 // full
records before
+ + AH._at; //
offset to our samples
+ string abuf (this_a, alen); // NULL-terminated,
possibly at pos <alen
+
+ time_t record_start = _start_time + r *
data_record_size;
+
+ float offset,
+ duration;
+ const char
+ *offset_p = abuf.c_str(),
+ *duration_p,
+ *tals_p;
+ printf( "here's one: %s\n", offset_p);
+ while ( (tals_p = index( offset_p, 21)) ) {
+ if ( (duration = 0.,
+ (duration_p = index( offset_p, 20))) &&
+ duration_p < tals_p ) {
+ offset = stof( string (offset_p,
duration_p - offset_p));
+ duration = stof( string (duration_p,
tals_p - duration_p));
+ } else
+ offset = stof( string (offset_p, tals_p
- offset_p));
+
+ auto tals = tokens( tals_p, (char)20);
+ for ( auto& t : tals )
+ common_annotations.emplace_back(
+ record_start + offset,
+ record_start + offset +
duration,
+ t,
+ SAnnotation::TType::plain);
+ }
}
+ } catch (invalid_argument& ex) {
+ fprintf( stderr, "Bad offset or duration of embedded
annotation\n");
+ return -1;
}
return 0;
--
Sleep experiment manager
_______________________________________________
debian-med-commit mailing list
[email protected]
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/debian-med-commit