Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Array subscript is above array bounds when compiling NLSF2A.c #7

Closed
rawr51919 opened this issue May 9, 2016 · 7 comments
Closed

Array subscript is above array bounds when compiling NLSF2A.c #7

rawr51919 opened this issue May 9, 2016 · 7 comments

Comments

@rawr51919
Copy link

rawr51919 commented May 9, 2016

I happened to come across this bug with spearmint, available at spearmint.pw. The description of this bug is, when you go to compile opus, the compiler gives out 4 warnings. Here's an excerpt of the warning as it happens:

CC code/opus-1.1/silk/NLSF2A.c
code/opus-1.1/silk/NLSF2A.c: In function ‘silk_NLSF2A’:
code/opus-1.1/silk/NLSF2A.c:121:17: warning: array subscript is above array bounds [-Warray-bounds]
Ptmp = P[ k+1 ] + P[ k ];
^
code/opus-1.1/silk/NLSF2A.c:122:17: warning: array subscript is above array bounds [-Warray-bounds]
Qtmp = Q[ k+1 ] - Q[ k ];
^
code/opus-1.1/silk/NLSF2A.c:121:17: warning: array subscript is above array bounds [-Warray-bounds]
Ptmp = P[ k+1 ] + P[ k ];
^
code/opus-1.1/silk/NLSF2A.c:122:17: warning: array subscript is above array bounds [-Warray-bounds]
Qtmp = Q[ k+1 ] - Q[ k ];
^

This also happens when compiling any project which uses opus, meaning it's probably also a bug with opus.

@rillian
Copy link
Contributor

rillian commented May 9, 2016

I think these are spurious. On line 89 we have

silk_assert( d==10||d==16 );

then on line 113, the loop bound is set to

dd = silk_RSHIFT( d, 1 );

so dd is either 5 or 8. Meanwhile the array itself is size SILK_MAX_ORDER_LPC / 2 + 1 which is 9 (by SigProc_FIX.h:38) so the k+1 array access is safe.

Any suggestions how we can silence the warning? Which compiler version shows the issue?

@rawr51919
Copy link
Author

Latest Cygwin, rillian. I'm currently using the x64 version.

@rillian
Copy link
Contributor

rillian commented May 9, 2016

what does gcc --version say?

@rawr51919
Copy link
Author

It reports gcc 5.3.0.

@rawr51919
Copy link
Author

rawr51919 commented May 10, 2016

zturtleman fixed this error in Spearmint. Here's the changelog for the error fix: zturtleman/spearmint@a3da9be

@rillian
Copy link
Contributor

rillian commented May 10, 2016

Thanks for the link. I'd rather not just turn the warning off, since it can find real bugs elsewhere.

Oddly, I can't reproduce with gcc 5.3 or 6.1 on linux, nor with cross-mingw32-gcc 6.1 on linux with the opus autotools build, and not with gcc 6.0 on linux with the spearmint build (although I do see array-bounds warnings for several other spearmint submodules). I also don't see any differences between the silk code in the opus master branch verses the spearmint fork which would change the array bound calculation.

@rillian rillian closed this as completed May 10, 2016
@rawr51919
Copy link
Author

He reverted the changes explained here because it broke compilation on Mac OS X 10.6.8.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants