Skip to content

Commit

Permalink
Merge pull request #664 from Antoniolm/release/7.3.0
Browse files Browse the repository at this point in the history
#651 #655: Fix overflow and eof issue
  • Loading branch information
Antoniolm authored Feb 22, 2024
2 parents 27240ef + c5d281b commit abdf417
Showing 1 changed file with 30 additions and 6 deletions.
36 changes: 30 additions & 6 deletions examples/recording_service/pluggable_storage/c/FileStorageReader.c
Original file line number Diff line number Diff line change
Expand Up @@ -442,9 +442,23 @@ void FileStorageStreamReader_read(
struct FileStorageStreamReader *stream_reader =
(struct FileStorageStreamReader *) stream_reader_data;
int i = 0;
long long timestamp_limit =
(long long) selector->time_range_end.sec * NANOSECS_PER_SEC
+ selector->time_range_end.nanosec;
/*
* If the last sample was already provided and we are at the end of the file
* we will skip the read operation in order to finalize the execution.
*/
if (stream_reader->current_timestamp == INT64_MAX
&& feof(stream_reader->file_record.file)) {
*count = 0;
return;
}
DDS_LongLong timestamp_limit;
if (selector->time_range_end.sec == DDS_TIME_MAX.sec
&& selector->time_range_end.nanosec == DDS_TIME_MAX.nanosec) {
timestamp_limit = selector->time_range_end.sec;
} else {
timestamp_limit = selector->time_range_end.sec * NANOSECS_PER_SEC;
timestamp_limit += selector->time_range_end.nanosec;
}
int read_samples = 0;
/*
* The value of the sample selector's max samples could be
Expand All @@ -461,12 +475,21 @@ void FileStorageStreamReader_read(
*count = 0;
return;
}
/* Add the currently read sample and sample info values to the taken data
* and info collections (sequences) */
/*
* Add the currently read sample and sample info values to the taken data
* and info collections (sequences)
*/
do {
FileStorageStreamReader_addSampleToData(stream_reader);
FileStorageStreamReader_readSample(stream_reader);
read_samples++;
/*
* if we reach the end of the file or we cant read a proper sample,
* we dont add that sample on this iteration but we should send the
* previous samples
*/
if (FileStorageStreamReader_readSample(stream_reader) == FALSE) {
break;
}
} while (stream_reader->current_timestamp <= timestamp_limit
&& read_samples < max_samples);
/* The number of taken samples is the current length of the data sequence */
Expand Down Expand Up @@ -583,6 +606,7 @@ int FileStorageStreamReader_initialize(
/* Bootstrap the take loop: read the first sample */
if (!FileStorageStreamReader_readSample(stream_reader)) {
printf("Failed to get first sample from file, maybe EOF was reached\n");
return FALSE;
}

RTI_RecordingServiceStorageStreamReader_initialize(
Expand Down

0 comments on commit abdf417

Please sign in to comment.