]> git.sesse.net Git - x264/commit
Fix float-cast-overflow in x264_ratecontrol_end function
authorAlexey Samsonov <vonosmas@gmail.com>
Tue, 26 Jan 2016 00:05:25 +0000 (16:05 -0800)
committerHenrik Gramner <henrik@gramner.com>
Fri, 5 Feb 2016 17:48:13 +0000 (18:48 +0100)
commitf86756985d42ac4a14866534c588061ede860b7b
tree857f8a3384b10971a30fec719c96d94e1860c96b
parenta01e33913655f983df7a4d64b0a4178abb1eb618
Fix float-cast-overflow in x264_ratecontrol_end function

According to the C standard, it is undefined behavior to cast a negative
floating point number to an unsigned integer. Float-cast-overflow in
general is known to produce different results on different architectures.

Building x264 code with Clang and -fsanitize=float-cast-overflow
(http://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html#availablle-checks)
and running it on some real-life examples occasionally produces errors
of the form:

encoder/ratecontrol.c:1892: runtime error: value -5011.14 is outside the
range of representable values of type 'unsigned short'

Fix these errors by explicitly coding the de-facto x86 behavior: casting
float to uint16_t through int16_t.
encoder/ratecontrol.c