summaryrefslogtreecommitdiff
path: root/sw
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 /sw
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 'sw')
-rw-r--r--sw/qa/core/uwriter.cxx16
-rw-r--r--sw/source/filter/ww8/docxattributeoutput.cxx9
2 files changed, 14 insertions, 11 deletions
diff --git a/sw/qa/core/uwriter.cxx b/sw/qa/core/uwriter.cxx
index ec62c05366ee..a739ca0c0e96 100644
--- a/sw/qa/core/uwriter.cxx
+++ b/sw/qa/core/uwriter.cxx
@@ -16,6 +16,7 @@
#include <com/sun/star/i18n/TransliterationModulesExtra.hpp>
#include <comphelper/processfactory.hxx>
+#include <comphelper/random.hxx>
#include <tools/urlobj.hxx>
#include <unotools/tempfile.hxx>
#include <unotools/transliterationwrapper.hxx>
@@ -849,7 +850,7 @@ getRand(int modulus)
{
if (modulus <= 0)
return 0;
- return rand() % modulus;
+ return comphelper::rng::uniform_int_distribution(0, modulus-1);
}
static OUString
@@ -869,12 +870,13 @@ static SwPosition
getRandomPosition(SwDoc *pDoc, int /* nOffset */)
{
const SwPosition aPos(pDoc->GetNodes().GetEndOfContent());
- sal_uLong nNodes = aPos.nNode.GetNode().GetIndex() - aPos.nNode.GetNode().StartOfSectionIndex();
- sal_uLong n = (rand() * nNodes) / RAND_MAX;
- SwPaM pam(aPos);
- for (sal_uLong i = 0; i < n; ++i) {
- pam.Move(fnMoveBackward, fnGoNode);
- }
+ sal_uLong nNodes = aPos.nNode.GetNode().GetIndex() - aPos.nNode.GetNode().StartOfSectionIndex();
+ sal_uLong n = comphelper::rng::uniform_int_distribution(static_cast<sal_uLong>(0), nNodes);
+ SwPaM pam(aPos);
+ for (sal_uLong i = 0; i < n; ++i)
+ {
+ pam.Move(fnMoveBackward, fnGoNode);
+ }
return *pam.GetPoint();
}
diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx
index 36b1f303b149..95b0ea42af9b 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -40,6 +40,7 @@
#include "wrtww8.hxx"
+#include <comphelper/random.hxx>
#include <comphelper/string.hxx>
#include <comphelper/flagguard.hxx>
#include <oox/token/tokens.hxx>
@@ -657,9 +658,9 @@ void DocxAttributeOutput::WriteSdtBlock( sal_Int32& nSdtPrToken,
if( nSdtPrToken == FSNS( XML_w, XML_id ) || ( bPara && m_bParagraphSdtHasId ) )
//Word won't open a document with an empty id tag, we fill it with a random number
- m_pSerializer->singleElementNS(XML_w, XML_id,
- FSNS(XML_w, XML_val), OString::number( rand() ),
- FSEND );
+ m_pSerializer->singleElementNS(XML_w, XML_id, FSNS(XML_w, XML_val),
+ OString::number(comphelper::rng::uniform_int_distribution(0, std::numeric_limits<int>::max())),
+ FSEND);
if(( pSdtPrDataBindingAttrs ) && !m_rExport.SdrExporter().IsParagraphHasDrawing())
{
@@ -4794,7 +4795,7 @@ void DocxAttributeOutput::WriteOLE( SwOLENode& rNode, const Size& rSize, const S
XML_ProgID, OUStringToOString( sProgID, RTL_TEXTENCODING_UTF8 ).getStr(),
XML_ShapeID, sShapeId.getStr(),
XML_DrawAspect, OUStringToOString( sDrawAspect, RTL_TEXTENCODING_UTF8 ).getStr(),
- XML_ObjectID, "_" + OString::number( rand() ),
+ XML_ObjectID, "_" + OString::number(comphelper::rng::uniform_int_distribution(0, std::numeric_limits<int>::max())),
FSNS( XML_r, XML_id ), sId.getStr(),
FSEND );