Add back in min/max check on fuzzer range
authorKevin Lubick <kjlubick@google.com>
Tue, 15 Nov 2016 21:07:02 +0000 (16:07 -0500)
committerSkia Commit-Bot <skia-commit-bot@chromium.org>
Wed, 16 Nov 2016 19:17:19 +0000 (19:17 +0000)
BUG=skia:

GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=4798

Change-Id: Ia93b4eeea82dd04f0c6bd287f61d26086a0aa740
Reviewed-on: https://skia-review.googlesource.com/4798
Reviewed-by: Kevin Lubick <kjlubick@google.com>
Commit-Queue: Kevin Lubick <kjlubick@google.com>

fuzz/Fuzz.h
fuzz/FuzzParsePath.cpp

index 559addb..8abbb22 100644 (file)
@@ -95,20 +95,19 @@ inline void Fuzz::nextRange(float* f, float min, float max) {
 template <typename T, typename Min, typename Max>
 inline void Fuzz::nextRange(T* n, Min min, Max max) {
     this->next<T>(n);
-    T range = max - min + 1;
-    if (0 == range) {
-        return;
-    } else {
-        if (*n < 0) { // Handle negatives
-            if (*n != std::numeric_limits<T>::lowest()) {
-                *n *= -1;
-            }
-            else {
-                *n = std::numeric_limits<T>::max();
-            }
-         }
-        *n = min + (*n % range);
+    if (min >= max) {
+        // Avoid misuse of nextRange
+        this->signalBug();
+    }
+    if (*n < 0) { // Handle negatives
+        if (*n != std::numeric_limits<T>::lowest()) {
+            *n *= -1;
+        }
+        else {
+            *n = std::numeric_limits<T>::max();
+        }
     }
+    *n = min + (*n % ((size_t)max - min + 1));
 }
 
 template <typename T>
index 90b99ca..b9d7f6b 100644 (file)
@@ -45,7 +45,7 @@ static void add_white(Fuzz* fuzz, SkString* atom) {
     fuzz->nextRange(&reps, 0, 2);
     for (uint8_t rep = 0; rep < reps; ++rep) {
         uint8_t index;
-        fuzz->nextRange(&index, 0, SK_ARRAY_COUNT(gWhiteSpace) - 1);
+        fuzz->nextRange(&index, 0, (int) SK_ARRAY_COUNT(gWhiteSpace) - 1);
         if (gWhiteSpace[index]) {
             atom->append(&gWhiteSpace[index], 1);
         }
@@ -75,7 +75,7 @@ static void add_comma(Fuzz* fuzz, SkString* atom) {
 SkString MakeRandomParsePathPiece(Fuzz* fuzz) {
     SkString atom;
     uint8_t index;
-    fuzz->nextRange(&index, 0, SK_ARRAY_COUNT(gLegal) - 1);
+    fuzz->nextRange(&index, 0, (int) SK_ARRAY_COUNT(gLegal) - 1);
     const Legal& legal = gLegal[index];
     gEasy ? atom.append("\n") : add_white(fuzz, &atom);
     bool b;