Commit 903c91cc authored by Frank Barchard's avatar Frank Barchard

fix for ubsan on unittest.h fastrand()

internal math of the fastrand function uses a multiply
and add that overflows a signed int.  This triggers a
ubsan failure:

../../unit_test/../unit_test/unit_test.h:60:33: runtime error: signed integer overflow: 56248274 * 214013 cannot be represented in type 'int'

This change casts the intermediate math to unsigned
int to avoid the overflow.

For more info on ubsan, see
http://dev.chromium.org/developers/testing/undefinedbehaviorsanitizer

TESTED=Passing compilation using:
GYP_DEFINES="ubsan=1"
GYP_DEFINES="ubsan_vptr=1"

R=harryjin@google.com, pbos@webrtc.org
BUG=libyuv:563

Review URL: https://codereview.chromium.org/1662453003 .
parent 05ed0c53
Name: libyuv Name: libyuv
URL: http://code.google.com/p/libyuv/ URL: http://code.google.com/p/libyuv/
Version: 1570 Version: 1571
License: BSD License: BSD
License File: LICENSE License File: LICENSE
......
...@@ -11,6 +11,6 @@ ...@@ -11,6 +11,6 @@
#ifndef INCLUDE_LIBYUV_VERSION_H_ // NOLINT #ifndef INCLUDE_LIBYUV_VERSION_H_ // NOLINT
#define INCLUDE_LIBYUV_VERSION_H_ #define INCLUDE_LIBYUV_VERSION_H_
#define LIBYUV_VERSION 1570 #define LIBYUV_VERSION 1571
#endif // INCLUDE_LIBYUV_VERSION_H_ NOLINT #endif // INCLUDE_LIBYUV_VERSION_H_ NOLINT
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
// TODO(fbarchard): Add command line parsing to pass this as option. // TODO(fbarchard): Add command line parsing to pass this as option.
#define BENCHMARK_ITERATIONS 1 #define BENCHMARK_ITERATIONS 1
int fastrand_seed = 0xfb; unsigned int fastrand_seed = 0xfb;
DEFINE_int32(libyuv_width, 0, "width of test image."); DEFINE_int32(libyuv_width, 0, "width of test image.");
DEFINE_int32(libyuv_height, 0, "height of test image."); DEFINE_int32(libyuv_height, 0, "height of test image.");
......
...@@ -55,10 +55,10 @@ static inline double get_time() { ...@@ -55,10 +55,10 @@ static inline double get_time() {
} }
#endif #endif
extern int fastrand_seed; extern unsigned int fastrand_seed;
inline int fastrand() { inline int fastrand() {
fastrand_seed = fastrand_seed * 214013 + 2531011; fastrand_seed = fastrand_seed * 214013u + 2531011u;
return (fastrand_seed >> 16) & 0xffff; return static_cast<int>((fastrand_seed >> 16) & 0xffff);
} }
static inline void MemRandomize(uint8* dst, int64 len) { static inline void MemRandomize(uint8* dst, int64 len) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment