用于Boost :: uuid的Valgrind日志分析 [英] Analysis of Valgrind log for boost::uuid
问题描述
我正在使用boost :: uuid来生成唯一的ID:
I am using boost::uuid in order to generate unique ids:
string UUid()
{
boost::uuids::uuid uuid = boost::uuids::random_generator()();
return boost::lexical_cast<std::string>(uuid);
}
当我使用valgrind
来分析我的代码时,我得到以下评论:
When I use valgrind
in order to analyse my code i get the following remarks:
==47807== Conditional jump or move depends on uninitialised value(s)
==47807== at 0x441D19: void boost::random::mersenne_twister_engine<unsigned int, 32ul, 624ul, 397ul, 31ul, 2567483615u, 11ul, 4294967295u, 7ul, 2636928640u, 15ul, 4022730752u, 18ul, 1812433253u>::seed<boost::uuids::detail::generator_iterator<boost::uuids::detail::seed_rng> >(boost::uuids::detail::generator_iterator<boost::uuids::detail::seed_rng>&, boost::uuids::detail::generator_iterator<boost::uuids::detail::seed_rng>) (mersenne_twister.hpp:177)
==47807== by 0x4417EC: void boost::uuids::detail::seed<boost::random::mersenne_twister_engine<unsigned int, 32ul, 624ul, 397ul, 31ul, 2567483615u, 11ul, 4294967295u, 7ul, 2636928640u, 15ul, 4022730752u, 18ul, 1812433253u> >(boost::random::mersenne_twister_engine<unsigned int, 32ul, 624ul, 397ul, 31ul, 2567483615u, 11ul, 4294967295u, 7ul, 2636928640u, 15ul, 4022730752u, 18ul, 1812433253u>&) (seed_rng.hpp:249)
==47807== by 0x440EAA: boost::uuids::basic_random_generator<boost::random::mersenne_twister_engine<unsigned int, 32ul, 624ul, 397ul, 31ul, 2567483615u, 11ul, 4294967295u, 7ul, 2636928640u, 15ul, 4022730752u, 18ul, 1812433253u> >::basic_random_generator() (random_generator.hpp:50)
==47807== by 0x43B4D5: ManageDb::randomid() (ManageDb.cpp:92)
==47807== by 0x43B57A: ManageDb::fillTables(std::vector<Entity, std::allocator<Entity> > const&) (ManageDb.cpp:103)
==47807== by 0x40BBF7: DataLoader::extractData() (DataLoader.cpp:78)
==47807== by 0x42EF26: main (main.cpp:30)
==47807== Uninitialised value was created by a heap allocation
==47807== at 0x4C2B0E0: operator new(unsigned long) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==47807== by 0x44042A: boost::uuids::detail::seed_rng::sha1_random_digest_() (seed_rng.hpp:167)
==47807== by 0x44025B: boost::uuids::detail::seed_rng::operator()() (seed_rng.hpp:103)
==47807== by 0x441C97: boost::uuids::detail::generator_iterator<boost::uuids::detail::seed_rng>::generator_iterator(boost::uuids::detail::seed_rng*) (seed_rng.hpp:218)
==47807== by 0x4417C5: void boost::uuids::detail::seed<boost::random::mersenne_twister_engine<unsigned int, 32ul, 624ul, 397ul, 31ul, 2567483615u, 11ul, 4294967295u, 7ul, 2636928640u, 15ul, 4022730752u, 18ul, 1812433253u> >(boost::random::mersenne_twister_engine<unsigned int, 32ul, 624ul, 397ul, 31ul, 2567483615u, 11ul, 4294967295u, 7ul, 2636928640u, 15ul, 4022730752u, 18ul, 1812433253u>&) (seed_rng.hpp:247)
==47807== by 0x440EAA: boost::uuids::basic_random_generator<boost::random::mersenne_twister_engine<unsigned int, 32ul, 624ul, 397ul, 31ul, 2567483615u, 11ul, 4294967295u, 7ul, 2636928640u, 15ul, 4022730752u, 18ul, 1812433253u> >::basic_random_generator() (random_generator.hpp:50)
==47807== by 0x43B4D5: ManageDb::randomid() (ManageDb.cpp:92)
==47807== by 0x43B57A: ManageDb::fillTables(std::vector<Entity, std::allocator<Entity> > const&) (ManageDb.cpp:103)
==47807== by 0x40BBF7: DataLoader::extractData() (DataLoader.cpp:78)
==47807== by 0x42EF26: main (main.cpp:30)
==47807==
问题
- 为什么
valgrind
为boost::uuid
生成这些注释? - 如果升压有问题,我可以忽略它吗?
- Why is
valgrind
generating these remarks forboost::uuid
? - If it's a problem in boost can I ignore it?
- 根据此链接门票7248(重新打开的错误)一个可能的错误.好的,如果是个错误,我该如何使valgrind忽略它?
- According to this link Ticket #7248 (reopened Bugs) it is a possible bug. Fine if is a bug how can I make valgrind ignore it?
Questions
valgrind --leak-check=full --track-origins=yes --suppressions=valgrind.supp ./MyProgram > valgrind-log.txt
valgrind.supp
# supression file for continuum with valgrind
# to generate each supression use: --gen-suppressions=yes option
# to use this supression file, use: --suppressions=<this filename>
{
Crypt_r
Memcheck:Cond
obj:/lib/libc-2.11.1.so
fun:__sha512_crypt_r
fun:crypt_r
}
{
Crypt_r use of uninitialised value of size 8
Memcheck:Value8
obj:/lib/libc-2.11.1.so
fun:__sha512_crypt_r
fun:crypt_r
}
{
String S_Create
Memcheck:Leak
fun:_Znwm
fun:_ZNSs4_Rep9_S_createEmmRKSaIcE
}
{
Mongo OID
Memcheck:Value8
fun:_ZN5mongo10toHexLowerEPKvi
fun:_ZNK5mongo3OID3strEv
}
推荐答案
请检查 http://www.boost.org/doc/libs/1_50_0/libs/uuid/uuid.html
boost::uuids::basic_random_generator class
的默认构造函数使用具有多个不同值(包括std::time(0)
,std::clock()
,**uninitialized data**
,value return from new unsigned int
等)的SHA-1散列为随机数生成器提供种子.
The boost::uuids::basic_random_generator class
default constructor seeds the random number generator with a SHA-1 hash of a number of different values including std::time(0)
, std::clock()
, **uninitialized data**
, value return from new unsigned int
, etc..
...使用Valgrind使用默认的boost :: uuids :: basic_random_generator构造函数会产生许多误报.一种解决方案是按Valgrind文档中所述消除错误.另一个解决方案是使用boost :: uuids :: basic_random_generator的不同构造函数,并显式传递随机数生成器.
...Using Valgrind produces a number of false positives with the default constructor of boost::uuids::basic_random_generator. One solution is to suppress the errors as described in Valgrind's documentation. Another solution is to use a different constructor of boost::uuids::basic_random_generator and explicitly pass in a random number generator.
这篇关于用于Boost :: uuid的Valgrind日志分析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!