diff options
author | bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2013-01-25 19:19:20 +0000 |
---|---|---|
committer | bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2013-01-25 19:19:20 +0000 |
commit | 6d5d08f14f1907d516ee28656dfd9ca063e0f7fc (patch) | |
tree | 3f3a00ea081ca2a159719e6c8d696dbe3ff5dbf7 /include | |
parent | 713276b143b87609a6c60b83f5fa789269ef6eda (diff) |
Fix nextRangeU(0, MAX_UINT) div by zero.
R=reed@google.com
Review URL: https://codereview.appspot.com/7201058
git-svn-id: http://skia.googlecode.com/svn/trunk@7400 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'include')
-rw-r--r-- | include/utils/SkRandom.h | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/include/utils/SkRandom.h b/include/utils/SkRandom.h index 73dc4917d7..d5f3123e02 100644 --- a/include/utils/SkRandom.h +++ b/include/utils/SkRandom.h @@ -69,7 +69,12 @@ public: */ uint32_t nextRangeU(uint32_t min, uint32_t max) { SkASSERT(min <= max); - return min + this->nextU() % (max - min + 1); + uint32_t range = max - min + 1; + if (0 == range) { + return this->nextU(); + } else { + return min + this->nextU() % range; + } } /** Return the next pseudo random unsigned number, mapped to lie within |