Boost logo

Boost Users :

Subject: [Boost-users] Use of uninitialized value in any_range
From: Auer, Jens (jens.auer_at_[hidden])
Date: 2015-10-15 06:17:16


Hi,

Valgrind reports multiple problems in our project which seem to come from boost::range::any_range. I was able to produce a small example which reproduces the problem:
#include <iostream>

#include <boost/range.hpp>
#include <boost/range/any_range.hpp>
#include <boost/range/adaptors.hpp>

struct Int
{
    Int(int i): x(i) {}
    int x;
};

int main( int argc, char* argv[] )
{
    typedef boost::any_range<Int*,
                             boost::forward_traversal_tag,
                             Int*,
                             std::ptrdiff_t> R;

    std::vector<std::unique_ptr<Int>> v;
    v.push_back( std::make_unique<Int>(42) );

    auto f = [](std::unique_ptr<Int> const& p) {return p.get();};
    R r = v | boost::adaptors::transformed(f);

    auto x = (*boost::begin(r))->x;
    std::cout << x << std::endl;
    return 0;
}

Running this, valgrind reports a "Use of uninitialized value of size 8":
# g++ --version
g++ (GCC) 5.2.0

# g++ -std=c++1y -o test test.cpp

# valgrind --version
valgrind-3.11.0

# valgrind --track-origins=yes ./test
==8119== Memcheck, a memory error detector
==8119== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al.
==8119== Using Valgrind-3.11.0 and LibVEX; rerun with -h for copyright info
==8119== Command: ./test
==8119==
==8119== Use of uninitialised value of size 8
==8119== at 0x4010B8: main (in /tmp/test)
==8119== Uninitialised value was created by a stack allocation
==8119== at 0x40315D: boost::range_detail::any_iterator<Int*, boost::iterators::forward_traversal_tag, Int*, long, boost::any_iterator_buffer<64ul> >::dereference() const (in /tmp/test)
==8119==
42
==8119==
==8119== HEAP SUMMARY:
==8119== in use at exit: 72,704 bytes in 1 blocks
==8119== total heap usage: 3 allocs, 2 frees, 72,716 bytes allocated
==8119==
==8119== LEAK SUMMARY:
==8119== definitely lost: 0 bytes in 0 blocks
==8119== indirectly lost: 0 bytes in 0 blocks
==8119== possibly lost: 0 bytes in 0 blocks
==8119== still reachable: 72,704 bytes in 1 blocks
==8119== suppressed: 0 bytes in 0 blocks
==8119== Rerun with --leak-check=full to see details of leaked memory
==8119==
==8119== For counts of detected and suppressed errors, rerun with: -v
==8119== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 1 from 1)

Best wishes,
  Jens

--
Jens Auer | CGI | Software-Engineer
CGI (Germany) GmbH & Co. KG
Rheinstraße 95 | 64295 Darmstadt | Germany
T: +49 6151 36860 154
jens.auer_at_[hidden]<mailto:jens.auer_at_[hidden]>
Unsere Pflichtangaben gemäß § 35a GmbHG / §§ 161, 125a HGB finden Sie unter de.cgi.com/pflichtangaben<http://de.cgi.com/pflichtangaben>.
CONFIDENTIALITY NOTICE: Proprietary/Confidential information belonging to CGI Group Inc. and its affiliates may be contained in this message. If you are not a recipient indicated or intended in this message (or responsible for delivery of this message to such person), or you think for any reason that this message may have been addressed to you in error, you may not use or copy or deliver this message to anyone else. In such case, you should destroy this message and are asked to notify the sender by reply e-mail.
--
Jens Auer | CGI | Software-Engineer
CGI (Germany) GmbH & Co. KG
Rheinstraße 95 | 64295 Darmstadt | Germany
T: +49 6151 36860 154
jens.auer_at_[hidden]<mailto:jens.auer_at_[hidden]>
Unsere Pflichtangaben gemäß § 35a GmbHG / §§ 161, 125a HGB finden Sie unter de.cgi.com/pflichtangaben<http://de.cgi.com/pflichtangaben>.
CONFIDENTIALITY NOTICE: Proprietary/Confidential information belonging to CGI Group Inc. and its affiliates may be contained in this message. If you are not a recipient indicated or intended in this message (or responsible for delivery of this message to such person), or you think for any reason that this message may have been addressed to you in error, you may not use or copy or deliver this message to anyone else. In such case, you should destroy this message and are asked to notify the sender by reply e-mail.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net