don't create out of range enums
UBSAN freaks out. Bug: oss-fuzz:19358 Change-Id: I7c5fc129042b8b30fb5f10fe56b97cf62877c9bf Reviewed-on: https://skia-review.googlesource.com/c/skia/+/259537 Commit-Queue: Mike Klein <mtklein@google.com> Commit-Queue: Brian Salomon <bsalomon@google.com> Auto-Submit: Mike Klein <mtklein@google.com> Reviewed-by: Brian Salomon <bsalomon@google.com>
This commit is contained in:
parent
a27d625ca6
commit
77d3694f40
12
fuzz/Fuzz.h
12
fuzz/Fuzz.h
@ -13,6 +13,7 @@
|
||||
#include "include/core/SkRegion.h"
|
||||
#include "include/core/SkTypes.h"
|
||||
#include "include/private/SkMalloc.h"
|
||||
#include "include/private/SkTFitsIn.h"
|
||||
#include "tools/Registry.h"
|
||||
|
||||
#include <limits>
|
||||
@ -98,9 +99,14 @@ inline void Fuzz::next(Arg* first, Args... rest) {
|
||||
|
||||
template <typename T, typename Min, typename Max>
|
||||
inline void Fuzz::nextRange(T* value, Min min, Max max) {
|
||||
this->next(value);
|
||||
if (*value < (T)min) { *value = (T)min; }
|
||||
if (*value > (T)max) { *value = (T)max; }
|
||||
// UBSAN worries if we make an enum with out of range values, even temporarily.
|
||||
using Raw = typename sk_strip_enum<T>::type;
|
||||
Raw raw;
|
||||
this->next(&raw);
|
||||
|
||||
if (raw < (Raw)min) { raw = (Raw)min; }
|
||||
if (raw > (Raw)max) { raw = (Raw)max; }
|
||||
*value = (T)raw;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
|
Loading…
Reference in New Issue
Block a user