basegfx/source/color/bcolormodifier.cxx |   20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

New commits:
commit 2ce749a428d1df2c659ecfdaf2e151dd07d3f1b3
Author:     Caolán McNamara <caol...@redhat.com>
AuthorDate: Wed Dec 21 14:23:10 2022 +0000
Commit:     Caolán McNamara <caol...@redhat.com>
CommitDate: Wed Dec 21 23:59:31 2022 +0000

    cid#1517814 Calling risky function
    
    Change-Id: I0451ac0375ad5a29a5bf65ebcc028ae44c43d934
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/144688
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caol...@redhat.com>

diff --git a/basegfx/source/color/bcolormodifier.cxx 
b/basegfx/source/color/bcolormodifier.cxx
index bd6157f373d5..f27ffcc9aaf0 100644
--- a/basegfx/source/color/bcolormodifier.cxx
+++ b/basegfx/source/color/bcolormodifier.cxx
@@ -18,10 +18,10 @@
  */
 
 #include <sal/config.h>
-
 #include <algorithm>
-
+#include <float.h>
 #include <basegfx/color/bcolormodifier.hxx>
+#include <comphelper/random.hxx>
 
 namespace basegfx
 {
@@ -304,17 +304,21 @@ namespace basegfx
         if(1.0 <= mfRandomPart)
         {
             // full randomized color
-            const double fMul(1.0 / RAND_MAX);
-            return basegfx::BColor(rand() * fMul, rand() * fMul, rand() * 
fMul);
+            return basegfx::BColor(
+                    comphelper::rng::uniform_real_distribution(0.0, 
nextafter(1.0, DBL_MAX)),
+                    comphelper::rng::uniform_real_distribution(0.0, 
nextafter(1.0, DBL_MAX)),
+                    comphelper::rng::uniform_real_distribution(0.0, 
nextafter(1.0, DBL_MAX)));
         }
 
         // mixed color
         const double fMulA(1.0 - mfRandomPart);
-        const double fMulB(mfRandomPart / RAND_MAX);
         return basegfx::BColor(
-            aSourceColor.getRed() * fMulA + rand() * fMulB,
-            aSourceColor.getGreen() * fMulA + rand() * fMulB,
-            aSourceColor.getBlue() * fMulA + rand() * fMulB);
+            aSourceColor.getRed() * fMulA +
+                comphelper::rng::uniform_real_distribution(0.0, 
nextafter(mfRandomPart, DBL_MAX)),
+            aSourceColor.getGreen() * fMulA +
+                comphelper::rng::uniform_real_distribution(0.0, 
nextafter(mfRandomPart, DBL_MAX)),
+            aSourceColor.getBlue() * fMulA +
+                comphelper::rng::uniform_real_distribution(0.0, 
nextafter(mfRandomPart, DBL_MAX)));
     }
 
     ::basegfx::BColor BColorModifierStack::getModifiedColor(const 
::basegfx::BColor& rSource) const

Reply via email to