# HG changeset patch # User Matti Hamalainen # Date 1349893389 -10800 # Node ID 31e62b1f1b6ec8e3b88b761a53ea8170eb41aa53 # Parent 3b5493fac9289bee5eafd007fc3d8a62e5a77441 Add boundary checks for the scope drawing. diff -r 3b5493fac928 -r 31e62b1f1b6e ppl.c --- a/ppl.c Wed Oct 10 20:45:10 2012 +0300 +++ b/ppl.c Wed Oct 10 21:23:09 2012 +0300 @@ -262,6 +262,7 @@ int xc, ym = y0 + (y1 - y0) / 2, vol = FP_GETH(chn->chVolume); int pitch = screen->pitch / sizeof(Uint32); + int len = chn->chSize; DMFixedPoint offs = chn->chPos; Uint32 coln = dmCol(0.0, 0.8, 0.0), colx = dmCol(1.0, 0, 0); Uint32 *pix = screen->pixels; @@ -276,14 +277,27 @@ if (chn->chData == NULL || !chn->chPlaying) return; - for (xc = x0 + 1; xc < x1 - 1; xc++) + if (chn->chDirection) { - Sint16 val = ym + (data[FP_GETH(offs)] * yh * vol) / (65535 * 255); - pix[xc + val * pitch] = coln; - if (chn->chDirection) + for (xc = x0 + 1; xc < x1 - 1; xc++) + { + if (FP_GETH(offs) >= len) + break; + Sint16 val = ym + (data[FP_GETH(offs)] * yh * vol) / (65535 * 255); + pix[xc + val * pitch] = coln; FP_ADD(offs, chn->chDeltaO); - else + } + } + else + { + for (xc = x0 + 1; xc < x1 - 1; xc++) + { + if (FP_GETH(offs) < 0) + break; + Sint16 val = ym + (data[FP_GETH(offs)] * yh * vol) / (65535 * 255); + pix[xc + val * pitch] = coln; FP_SUB(offs, chn->chDeltaO); + } } }