comparison base/ColumnOp.h @ 1198:b494439a301c spectrogram-minor-refactor

Avoid overrun-by-1
author Chris Cannam
date Wed, 03 Aug 2016 14:19:56 +0100
parents fbe0fd84cb50
children 6f7a440b6218
comparison
equal deleted inserted replaced
1197:fbe0fd84cb50 1198:b494439a301c
153 static Column distribute(const Column &in, 153 static Column distribute(const Column &in,
154 int h, 154 int h,
155 const std::vector<double> &binfory, 155 const std::vector<double> &binfory,
156 int minbin, 156 int minbin,
157 bool interpolate) { 157 bool interpolate) {
158 158
159 std::vector<float> out(h, 0.f); 159 std::vector<float> out(h, 0.f);
160 int bins = int(in.size()); 160 int bins = int(in.size());
161 161
162 for (int y = 0; y < h; ++y) { 162 for (int y = 0; y < h; ++y) {
163 163
192 } else { // not interpolating this one 192 } else { // not interpolating this one
193 193
194 int by0 = int(sy0 + 0.0001); 194 int by0 = int(sy0 + 0.0001);
195 int by1 = int(sy1 + 0.0001); 195 int by1 = int(sy1 + 0.0001);
196 if (by1 < by0 + 1) by1 = by0 + 1; 196 if (by1 < by0 + 1) by1 = by0 + 1;
197 197 if (by1 >= bins) by1 = by1 - 1;
198
198 for (int bin = by0; bin < by1; ++bin) { 199 for (int bin = by0; bin < by1; ++bin) {
199 200
200 float value = in[bin]; 201 float value = in[bin];
201 202
202 if (value > out[y]) { 203 if (value > out[y]) {