Skip to content

Commit 6891cee

Browse files
committed
fbtl/posix: fix length calculation for data sieving
This commit fixes the calculation of the buffer length that needs to be read when using data sieving. The original code implicitely assumed that the ub of an iov at index j+1 is larger than the ub of the iov at index j. This is not necessarily the case for read operations. Hence, the code needs to keep track of the max. ub found. Fixes issue #10546 Signed-off-by: Edgar Gabriel <[email protected]>
1 parent e1b66cf commit 6891cee

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

ompi/mca/fbtl/posix/fbtl_posix_preadv.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,8 @@ ssize_t mca_fbtl_posix_preadv_datasieving (ompio_file_t *fh, struct flock *lock,
160160
}
161161

162162
size_t sstart = (size_t)fh->f_io_array[startindex].offset;
163-
size_t slen=0;
163+
size_t slen=0, maxlen=0;
164+
int maxindex = startindex;
164165

165166
for ( j = startindex; j < fh->f_num_of_io_entries; j++ ) {
166167
endindex = j;
@@ -169,15 +170,19 @@ ssize_t mca_fbtl_posix_preadv_datasieving (ompio_file_t *fh, struct flock *lock,
169170
endindex = j-1;
170171
break;
171172
}
173+
if (slen > maxlen) {
174+
maxlen = slen;
175+
maxindex = endindex;
176+
}
172177
}
173178
// Need to increment the value of endindex
174179
// by one for the loop syntax to work correctly.
175180
endindex++;
176181

177182
start = (size_t)fh->f_io_array[startindex].offset;
178-
end = (size_t)fh->f_io_array[endindex-1].offset + fh->f_io_array[endindex-1].length;
183+
end = (size_t)fh->f_io_array[maxindex].offset + fh->f_io_array[maxindex].length;
179184
len = end - start;
180-
185+
181186
if ( len > bufsize ) {
182187
if ( NULL != temp_buf ) {
183188
free ( temp_buf);

0 commit comments

Comments
 (0)