summaryrefslogtreecommitdiff
path: root/sd
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2014-10-03 17:12:23 +0100
committerCaolán McNamara <caolanm@redhat.com>2014-10-06 14:13:27 +0100
commit8f436d3de7e99268a8862664d2cb2574231c3b18 (patch)
tree0a07dd3cecbd7bc5b0293006bb8691e33c5cca75 /sd
parente5ab3685550cf35c3eb9cb47530044f2d86433d5 (diff)
use comphelper::rng::uniform_*_distribution everywhere
and automatically seed from time on first use coverity#1242393 Don't call rand coverity#1242404 Don't call rand coverity#1242410 Don't call rand and additionally allow 0xFF as a value coverity#1242409 Don't call rand coverity#1242399 Don't call rand coverity#1242372 Don't call rand coverity#1242377 Don't call rand coverity#1242378 Don't call rand coverity#1242379 Don't call rand coverity#1242382 Don't call rand coverity#1242383 Don't call rand coverity#1242402 Don't call rand coverity#1242397 Don't call rand coverity#1242390 Don't call rand coverity#1242389 Don't call rand coverity#1242388 Don't call rand coverity#1242386 Don't call rand coverity#1242384 Don't call rand coverity#1242394 Don't call rand Change-Id: I241feab9cb370e091fd6ccaba2af941eb95bc7cf
Diffstat (limited to 'sd')
-rw-r--r--sd/source/core/CustomAnimationPreset.cxx7
-rw-r--r--sd/source/ui/remotecontrol/AvahiNetworkService.cxx5
2 files changed, 7 insertions, 5 deletions
diff --git a/sd/source/core/CustomAnimationPreset.cxx b/sd/source/core/CustomAnimationPreset.cxx
index b070733c6f30..09ba6a5e5820 100644
--- a/sd/source/core/CustomAnimationPreset.cxx
+++ b/sd/source/core/CustomAnimationPreset.cxx
@@ -30,6 +30,7 @@
#include <com/sun/star/beans/NamedValue.hpp>
#include <unotools/streamwrap.hxx>
#include <comphelper/processfactory.hxx>
+#include <comphelper/random.hxx>
#include <comphelper/string.hxx>
#include <unotools/pathoptions.hxx>
#include <tools/stream.hxx>
@@ -576,12 +577,12 @@ Reference< XAnimationNode > CustomAnimationPresets::getRandomPreset( sal_Int16 n
if( pCategoryList && pCategoryList->size() )
{
- sal_Int32 nCategory = (rand() * pCategoryList->size() / RAND_MAX);
+ sal_Int32 nCategory = comphelper::rng::uniform_int_distribution(static_cast<size_t>(0), pCategoryList->size()-1);
PresetCategoryPtr pCategory = (*pCategoryList)[nCategory];
if( pCategory.get() && !pCategory->maEffects.empty() )
{
- sal_Int32 nDescriptor = (rand() * pCategory->maEffects.size() / RAND_MAX);
+ sal_Int32 nDescriptor = comphelper::rng::uniform_int_distribution(static_cast<size_t>(0), pCategory->maEffects.size()-1);
CustomAnimationPresetPtr pPreset = pCategory->maEffects[nDescriptor];
if( pPreset.get() )
{
@@ -590,7 +591,7 @@ Reference< XAnimationNode > CustomAnimationPresets::getRandomPreset( sal_Int16 n
OUString aSubType;
if( !aSubTypes.empty() )
{
- sal_Int32 nSubType = (rand() * aSubTypes.size() / RAND_MAX);
+ size_t nSubType = comphelper::rng::uniform_int_distribution(static_cast<size_t>(0), aSubTypes.size()-1);
aSubType = aSubTypes[nSubType];
}
xNode = pPreset->create( aSubType );
diff --git a/sd/source/ui/remotecontrol/AvahiNetworkService.cxx b/sd/source/ui/remotecontrol/AvahiNetworkService.cxx
index ad2bfef61aff..9f53c5d5c16c 100644
--- a/sd/source/ui/remotecontrol/AvahiNetworkService.cxx
+++ b/sd/source/ui/remotecontrol/AvahiNetworkService.cxx
@@ -20,7 +20,7 @@
#include <avahi-common/error.h>
#include <avahi-common/timeval.h>
#include <avahi-common/thread-watch.h>
-
+#include <comphelper/random.hxx>
#include <dbus/dbus.h>
#include <sal/log.hxx>
@@ -99,7 +99,8 @@ static bool create_services(AvahiClient *c) {
if (avahi_entry_group_is_empty(group)) {
SAL_INFO("sdremote.wifi", "Adding service '" << avahiService->getName() << "'");
char r[128];
- snprintf(r, sizeof(r), "random=%i", rand());
+ int nRandom = comphelper::rng::uniform_int_distribution(0, std::numeric_limits<int>::max());
+ snprintf(r, sizeof(r), "random=%i", nRandom);
int ret = avahi_entry_group_add_service(
group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, static_cast<AvahiPublishFlags>(0),
avahiService->getName().c_str(), kREG_TYPE, NULL, NULL, 1599, "local", r, NULL