Skip to content

Commit

Permalink
Always reset bins history when loading data
Browse files Browse the repository at this point in the history
Fixes a possible crash on update, which happens if an empty history was
previously loaded, and the SNR data in the update is also empty.
  • Loading branch information
janh committed Feb 4, 2025
1 parent c9a03b5 commit f0f3a5c
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions history/bins_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,15 +173,17 @@ func (h *Bins) readBinsSNRMinMax(r io.Reader, data *snrMinMax) error {
return err
}

// Ensure that data structures are initialized

data.Reset(int(header.OriginalGroupSize), int(header.OriginalCount),
h.config.MaxBinCount, h.config.PeriodCount)

// Read data if available

if header.OriginalGroupSize == 0 || header.OriginalCount == 0 {
return nil
}

data.Reset(int(header.OriginalGroupSize), int(header.OriginalCount),
h.config.MaxBinCount, h.config.PeriodCount)

if h.config.PeriodCount > 0 {
for i := 0; i < h.config.PeriodCount; i++ {
err = h.readBinsFloatMinMax(r, &data.Periods[i])
Expand Down

0 comments on commit f0f3a5c

Please sign in to comment.