[ioquake3] 05/39: snd_wavelet: avoid undefined pointer below array bounds
Simon McVittie
smcv at debian.org
Sat Nov 5 20:26:21 UTC 2016
This is an automated email from the git hooks/post-receive script.
smcv pushed a commit to branch debian/master
in repository ioquake3.
commit c5b6bb0d4bd8006b89f308021e0bc5450769b590
Author: Simon McVittie <smcv at debian.org>
Date: Sun Sep 25 16:43:54 2016 +0100
snd_wavelet: avoid undefined pointer below array bounds
Given an array b[] of length n, pointers to &b[0]..&b[n] are defined
(where only &b[0]..&b[n-1] can be validly dereferenced). &b[-1], or
equivalently b-1, is not something we can use in valid Standard C.
gcc 6 diagnoses this as:
code/client/snd_wavelet.c:33:9: warning: array subscript is below array bounds [-Warray-bounds]
and might take this undefined behaviour as permission to emit
"more efficient" object code that is not what the author expected,
for example nothing at all. Use a macro to fake a 1-based array instead.
---
code/client/snd_wavelet.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/code/client/snd_wavelet.c b/code/client/snd_wavelet.c
index 3d8f5c7..e051da2 100644
--- a/code/client/snd_wavelet.c
+++ b/code/client/snd_wavelet.c
@@ -30,7 +30,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
void daub4(float b[], unsigned long n, int isign)
{
float wksp[4097] = { 0.0f };
- float *a=b-1; // numerical recipies so a[1] = b[0]
+#define a(x) b[(x)-1] // numerical recipies so a[1] = b[0]
unsigned long nh,nh1,i,j;
@@ -39,22 +39,23 @@ void daub4(float b[], unsigned long n, int isign)
nh1=(nh=n >> 1)+1;
if (isign >= 0) {
for (i=1,j=1;j<=n-3;j+=2,i++) {
- wksp[i] = C0*a[j]+C1*a[j+1]+C2*a[j+2]+C3*a[j+3];
- wksp[i+nh] = C3*a[j]-C2*a[j+1]+C1*a[j+2]-C0*a[j+3];
+ wksp[i] = C0*a(j)+C1*a(j+1)+C2*a(j+2)+C3*a(j+3);
+ wksp[i+nh] = C3*a(j)-C2*a(j+1)+C1*a(j+2)-C0*a(j+3);
}
- wksp[i ] = C0*a[n-1]+C1*a[n]+C2*a[1]+C3*a[2];
- wksp[i+nh] = C3*a[n-1]-C2*a[n]+C1*a[1]-C0*a[2];
+ wksp[i ] = C0*a(n-1)+C1*a(n)+C2*a(1)+C3*a(2);
+ wksp[i+nh] = C3*a(n-1)-C2*a(n)+C1*a(1)-C0*a(2);
} else {
- wksp[1] = C2*a[nh]+C1*a[n]+C0*a[1]+C3*a[nh1];
- wksp[2] = C3*a[nh]-C0*a[n]+C1*a[1]-C2*a[nh1];
+ wksp[1] = C2*a(nh)+C1*a(n)+C0*a(1)+C3*a(nh1);
+ wksp[2] = C3*a(nh)-C0*a(n)+C1*a(1)-C2*a(nh1);
for (i=1,j=3;i<nh;i++) {
- wksp[j++] = C2*a[i]+C1*a[i+nh]+C0*a[i+1]+C3*a[i+nh1];
- wksp[j++] = C3*a[i]-C0*a[i+nh]+C1*a[i+1]-C2*a[i+nh1];
+ wksp[j++] = C2*a(i)+C1*a(i+nh)+C0*a(i+1)+C3*a(i+nh1);
+ wksp[j++] = C3*a(i)-C0*a(i+nh)+C1*a(i+1)-C2*a(i+nh1);
}
}
for (i=1;i<=n;i++) {
- a[i]=wksp[i];
+ a(i)=wksp[i];
}
+#undef a
}
void wt1(float a[], unsigned long n, int isign)
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-games/ioquake3.git
More information about the Pkg-games-commits
mailing list