[Libreoffice-commits] core.git: 3 commits - sw/source
Michael Stahl
mstahl at redhat.com
Mon Oct 31 09:32:50 UTC 2016
sw/source/core/crsr/bookmrk.cxx | 9 ++++-----
sw/source/core/doc/DocumentListsManager.cxx | 14 ++++++--------
sw/source/core/doc/doc.cxx | 8 +++-----
sw/source/core/doc/docnew.cxx | 7 ++-----
sw/source/core/doc/docnum.cxx | 9 ++++-----
5 files changed, 19 insertions(+), 28 deletions(-)
New commits:
commit 3b921a2cd7c2b29245af4e975da6c60f72384237
Author: Michael Stahl <mstahl at redhat.com>
Date: Mon Oct 31 10:00:11 2016 +0100
sw: bookmark names don't need cryptographic randomness
Change-Id: I6cecbf9b5a8b66de2e0e2d90fdecf6b389caad25
diff --git a/sw/source/core/crsr/bookmrk.cxx b/sw/source/core/crsr/bookmrk.cxx
index 2ba5c11..3b93e30 100644
--- a/sw/source/core/crsr/bookmrk.cxx
+++ b/sw/source/core/crsr/bookmrk.cxx
@@ -31,10 +31,10 @@
#include <swtypes.hxx>
#include <UndoBookmark.hxx>
#include <unobookmark.hxx>
-#include <rtl/random.h>
#include <o3tl/make_unique.hxx>
#include <xmloff/odffields.hxx>
#include <libxml/xmlwriter.h>
+#include <comphelper/random.hxx>
#include <comphelper/anytostring.hxx>
using namespace ::sw::mark;
@@ -206,15 +206,14 @@ namespace sw { namespace mark
}
else
{
- static rtlRandomPool aPool = rtl_random_createPool();
static OUString sUniquePostfix;
static sal_Int32 nCount = SAL_MAX_INT32;
OUStringBuffer aResult(rPrefix);
if(nCount == SAL_MAX_INT32)
{
- sal_Int32 nRandom;
- rtl_random_getBytes(aPool, &nRandom, sizeof(nRandom));
- sUniquePostfix = OUStringBuffer(13).append('_').append(static_cast<sal_Int32>(abs(nRandom))).makeStringAndClear();
+ unsigned int const n(comphelper::rng::uniform_uint_distribution(0,
+ std::numeric_limits<unsigned int>::max()));
+ sUniquePostfix = "_" + OUString::number(n);
nCount = 0;
}
// putting the counter in front of the random parts will speed up string comparisons
commit f28f87f20c040d941d7a5e64c6b662a23744a21b
Author: Michael Stahl <mstahl at redhat.com>
Date: Fri Oct 28 23:45:40 2016 +0200
sw: RSID have no need for cryptographic randomness
Change-Id: I4a3c4e390a6d05059e27ca33f02c38cfb6bb2e47
diff --git a/sw/source/core/doc/doc.cxx b/sw/source/core/doc/doc.cxx
index 6aea833..e3ae223 100644
--- a/sw/source/core/doc/doc.cxx
+++ b/sw/source/core/doc/doc.cxx
@@ -42,7 +42,6 @@
#include <hintids.hxx>
#include <tools/globname.hxx>
#include <svx/svxids.hrc>
-#include <rtl/random.h>
#include <com/sun/star/i18n/WordType.hpp>
#include <com/sun/star/i18n/ForbiddenCharacters.hpp>
@@ -52,6 +51,7 @@
#include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
#include <com/sun/star/document/XDocumentProperties.hpp>
#include <comphelper/string.hxx>
+#include <comphelper/random.hxx>
#include <tools/urlobj.hxx>
#include <tools/poly.hxx>
#include <tools/multisel.hxx>
@@ -245,10 +245,8 @@ void SwDoc::setRsid( sal_uInt32 nVal )
{
// Increase the rsid with a random number smaller than 2^17. This way we
// expect to be able to edit a document 2^12 times before rsid overflows.
- static rtlRandomPool aPool = rtl_random_createPool();
- rtl_random_getBytes( aPool, &nIncrease, sizeof ( nIncrease ) );
- nIncrease &= ( 1<<17 ) - 1;
- nIncrease++; // make sure the new rsid is not the same
+ // start from 1 to ensure the new rsid is not the same
+ nIncrease = comphelper::rng::uniform_uint_distribution(1, (1 << 17) - 1);
}
mnRsid = nVal + nIncrease;
}
diff --git a/sw/source/core/doc/docnew.cxx b/sw/source/core/doc/docnew.cxx
index 8cd2dc9..37cb122 100644
--- a/sw/source/core/doc/docnew.cxx
+++ b/sw/source/core/doc/docnew.cxx
@@ -28,9 +28,9 @@
#include <com/sun/star/text/XFlatParagraphIteratorProvider.hpp>
#include <comphelper/processfactory.hxx>
+#include <comphelper/random.hxx>
#include <vcl/svapp.hxx>
#include <vcl/virdev.hxx>
-#include <rtl/random.h>
#include <sfx2/printer.hxx>
#include <sfx2/docfile.hxx>
#include <sfx2/frame.hxx>
@@ -367,10 +367,7 @@ SwDoc::SwDoc()
{
// Initialize the session id of the current document to a random number
// smaller than 2^21.
- static rtlRandomPool aPool = rtl_random_createPool();
- rtl_random_getBytes( aPool, &mnRsid, sizeof ( mnRsid ) );
- mnRsid &= ( 1<<21 ) - 1;
- mnRsid++;
+ mnRsid = comphelper::rng::uniform_uint_distribution(1, (1 << 21) - 1);
}
mnRsidRoot = mnRsid;
commit 9fd3a83e47e94801e6f4c9a432e8459b8320aabc
Author: Michael Stahl <mstahl at redhat.com>
Date: Fri Oct 28 22:54:32 2016 +0200
sw: DocumentListsManager: no need for cryptographic randomness here
... or in SwDoc::GetUniqueNumRuleName()
Change-Id: Ifd6df902f7feae9db77f38654d7eb246dfb3510a
diff --git a/sw/source/core/doc/DocumentListsManager.cxx b/sw/source/core/doc/DocumentListsManager.cxx
index 7b071ee..18554d6 100644
--- a/sw/source/core/doc/DocumentListsManager.cxx
+++ b/sw/source/core/doc/DocumentListsManager.cxx
@@ -20,7 +20,9 @@
#include <doc.hxx>
#include <list.hxx>
#include <numrule.hxx>
-#include <rtl/random.h>
+
+#include <comphelper/random.hxx>
+
#include <vector>
@@ -230,13 +232,9 @@ const OUString DocumentListsManager::CreateUniqueListId()
else
{
// #i92478#
- OUString aNewListId( "list" );
- // #o12311627#
- static rtlRandomPool s_RandomPool( rtl_random_createPool() );
- sal_Int64 n;
- rtl_random_getBytes( s_RandomPool, &n, sizeof(n) );
- aNewListId += OUString::number( (n < 0 ? -n : n) );
-
+ unsigned int const n(comphelper::rng::uniform_uint_distribution(0,
+ std::numeric_limits<unsigned int>::max()));
+ OUString const aNewListId = "list" + OUString::number(n);
return MakeListIdUnique( aNewListId );
}
}
diff --git a/sw/source/core/doc/docnum.cxx b/sw/source/core/doc/docnum.cxx
index 21e1726..46b70f4 100644
--- a/sw/source/core/doc/docnum.cxx
+++ b/sw/source/core/doc/docnum.cxx
@@ -18,7 +18,6 @@
*/
#include <hintids.hxx>
-#include <rtl/random.h>
#include <tools/resid.hxx>
#include <editeng/lrspitem.hxx>
#include <ftninfo.hxx>
@@ -55,6 +54,7 @@
#include <list.hxx>
#include <calbck.hxx>
#include <comphelper/string.hxx>
+#include <comphelper/random.hxx>
#include <tools/datetimeutils.hxx>
#include <cstdlib>
@@ -2210,10 +2210,9 @@ OUString SwDoc::GetUniqueNumRuleName( const OUString* pChkStr, bool bAutoNum ) c
}
else
{
- static rtlRandomPool s_RandomPool( rtl_random_createPool() );
- sal_Int64 n;
- rtl_random_getBytes( s_RandomPool, &n, sizeof(n) );
- aName = OUString::number( (n < 0 ? -n : n) );
+ unsigned int const n(comphelper::rng::uniform_uint_distribution(0,
+ std::numeric_limits<unsigned int>::max()));
+ aName = OUString::number(n);
}
if( pChkStr && pChkStr->isEmpty() )
pChkStr = nullptr;
More information about the Libreoffice-commits
mailing list