Note that there are some explanatory texts on larger screens.

plurals
  1. POvalgrind reports uninitialised value in BSONObj::toString with a simple BSON object created with GENOID
    primarykey
    data
    text
    <p>Using valgrind on a very simple example from the C++ driver of mongodb, it appears that something is wrong as soon as we use GENOID explicitly in the definition of a BSONObj. Here is an example that illustrates the problem:</p> <p>(tested on gcc 4.4.5, boost 1.42, debian 6, mongodb C++ driver 2.2)</p> <pre><code>#include &lt;cstdio&gt; #include &lt;string&gt; #include "mongo/db/jsobj.h" main() { mongo::BSONObj p = BSON( mongo::GENOID &lt;&lt; "name" &lt;&lt; "Joe" &lt;&lt; "age" &lt;&lt; 33 ); std::string s = p.toString(); std::cout &lt;&lt; s; } </code></pre> <p>When run with valgrind, we get this message:</p> <pre><code>==2506== Use of uninitialised value of size 8 ==2506== at 0x40A66B: mongo::toHexLower(void const*, int) (hex.h:64) ==2506== by 0x40A73F: mongo::OID::str() const (oid.h:66) ==2506== by 0x40A798: mongo::operator&lt;&lt;(mongo::StringBuilderImpl&lt;mongo::TrivialAllocator&gt;&amp;, mongo::OID const&amp;) (oid.h:140) ==2506== by 0x40DCC1: mongo::BSONElement::toString(mongo::StringBuilderImpl&lt;mongo::TrivialAllocator&gt;&amp;, bool, bool, int) const (bson-inl.h:765) ==2506== by 0x40C898: mongo::BSONObj::toString(mongo::StringBuilderImpl&lt;mongo::TrivialAllocator&gt;&amp;, bool, bool, int) const (bson-inl.h:475) ==2506== by 0x40C5A5: mongo::BSONObj::toString(bool, bool) const (bson-inl.h:445) ==2506== by 0x40A1B8: main (mongobug.cc:10) </code></pre> <p>If I remove the GENOID from the BSONObj definition, the problem is gone. This is a minimalist version of a more complex but similar problem I have when I use mongo::OID::gen() in my project.</p> <p>The example above is taken from the official mongodb C++ driver tutorial here: <a href="http://www.mongodb.org/pages/viewpage.action?pageId=133415#C%2B%2BTutorial-BSON" rel="nofollow">http://www.mongodb.org/pages/viewpage.action?pageId=133415#C%2B%2BTutorial-BSON</a></p> <p>Any idea what could be wrong? Thanks,</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload