mspass-team / mspass

Massive Parallel Analysis System for Seismologists
https://mspass.org
BSD 3-Clause "New" or "Revised" License
30 stars 12 forks source link

fix array bug in fileio #461

Closed Aristoeu closed 12 months ago

Aristoeu commented 1 year ago

I found when running the code below, index out of range error occurs.

db.save_ensemble_data_binary_file(e,dir=dir,dfile=dfile)

Reason: In fwrite_to_file function, dead data is skipped and its foff is not added to the foffs array, so the array is shorter than the length of the ensemble. However, the save_ensemble_data_binary_file function thinks the foffs array has the same length of the ensemble, so the index is out of range.

My fix is also adding a foff(0) for the dead object, it will not be used but can prevent the index error.

codecov[bot] commented 1 year ago

Codecov Report

Merging #461 (7bae206) into master (23898f4) will increase coverage by 0.02%. Report is 2 commits behind head on master. The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master     #461      +/-   ##
==========================================
+ Coverage   54.28%   54.31%   +0.02%     
==========================================
  Files         144      144              
  Lines       21953    21956       +3     
==========================================
+ Hits        11918    11925       +7     
+ Misses      10035    10031       -4     
Files Coverage Δ
cxx/src/lib/io/fileio.cc 65.02% <100.00%> (+0.58%) :arrow_up:

... and 1 file with indirect coverage changes

:mega: We’re building smart automated test selection to slash your CI/CD build times. Learn more