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

Two undefined behaviors by bitshifting of negative values #21

Open
kecsap opened this issue May 23, 2017 · 0 comments
Open

Two undefined behaviors by bitshifting of negative values #21

kecsap opened this issue May 23, 2017 · 0 comments

Comments

@kecsap
Copy link

kecsap commented May 23, 2017

Clang's sanitizers complain about bitshifting of negative values on 64-bit Ubuntu Linux:

1:

libvorbis/src/floor1.c:840:24: runtime error: left shift of negative value -2
#0 0x7f34f64c3eb1 in floor1_encode libvorbis/src/floor1.c
#1 0x7f34f650acd0 in mapping0_forward libvorbis/src/mapping0.c:625:20
#2 0x7f34f64b0035 in vorbis_analysis libvorbis/src/analysis.c:47:11

Fix:

libvorbis/src/floor1.c:

- val=-1-(val<<1);
+ val=-1-(val*2);

2:

libvorbis/src/psy.c:320:24: runtime error: left shift of negative value -11
#0 0x7fdfedcec8b5 in _vp_psy_init libvorbis/src/psy.c:320:24
#1 0x7fdfedcfc87b in _vds_shared_init libvorbis/src/block.c:225:7
#2 0x7fdfedcfbf6d in vorbis_analysis_init libvorbis/src/block.c:298:6

Fix:

libvorbis/src/psy.c:
- p->bark[i]=((lo-1)<<16)+(hi-1);
+ p->bark[i]=((lo-1)*65536)+(hi-1);

@kecsap kecsap changed the title Two undefined behaviors of bitshifting of negative values Two undefined behaviors by bitshifting of negative values May 23, 2017
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

1 participant