title: Segmentation fault in std::map::insert(...)
body: <p>i've used search but i didn't find answer satisfying me... so.. this is chunk of code:</p>
  
  <pre><code> //VoteContainer.h    
      typedef uint32_t order_id_t;
      typedef int driver_id_t;
  
      class Vote {
  
          public:
              enum DriverVoteResponse {YES, NO, TIMEOUT};
  
              struct DriverResponse {
                  driver_id_t driver_id;
                  time_t time;
                  DriverVoteResponse response;
              };
  
              Vote() : m_order_id(0), m_time_until(0) {};
              Vote(order_id_t inOrderId, std::vector&lt;driver_id_t&gt; inPermittedDrivers, int inSeconds);
              Vote(const Vote &amp; other) : m_order_id(other.m_order_id), m_time_until(other.m_order_id) {
                  m_drivers_responses = other.m_drivers_responses;
                  m_permitted_drivers = other.m_permitted_drivers;
              };
  
              virtual ~Vote() {};
  
              virtual void addDriverVote(driver_id_t inDriverId, DriverVoteResponse inDriverResponse);
              virtual void getAppropriateDriverId(driver_id_t * inDriverId); //with min response time
  
          private:
  
              order_id_t m_order_id;
              time_t m_time_until;
              std::vector&lt;DriverResponse&gt; m_drivers_responses;
              std::vector&lt;driver_id_t&gt; m_permitted_drivers;
          };
  
  class VoteContainer {
  public:
  
      VoteContainer() {};
      virtual ~VoteContainer() {};
  
      void registerVote(order_id_t inOrderId, std::vector&lt;driver_id_t&gt; inPermittedDrivers, int inSeconds);
  
  private:
      std::map&lt;order_id_t, Vote&gt; m_votes;
  };
  </code></pre>
  
  <p>and how i use it:</p>
  
  <pre><code>//VoteContainer.cpp
  void VoteContainer::registerVote(order_id_t inOrderId, std::vector&lt;driver_id_t&gt; inPermittedDrivers, int inSeconds) {
          m_votes.insert(std::make_pair(inOrderId,  Vote(inOrderId, inPermittedDrivers, inSeconds)));
      return;
  };
  </code></pre>
  
  <p>i have segfault in regardless of what i do:</p>
  
  <pre><code>m_votes.insert(std::make_pair(inOrderId,  Vote(inOrderId, inPermittedDrivers, inSeconds)));
  </code></pre>
  
  <p>i've tried to use std::map::find(...) first, but i have same result. backtrace:</p>
  
  <pre><code>#0 0x41096a std::less&lt;unsigned int&gt;::operator() (this=0x407a59, __x=@0x7fffffff0b50, __y=@0x758948f87d894905) (/usr/include/c++/4.4/bits/stl_function.h:230)
  #1 0x4105fb std::_Rb_tree&lt;unsigned int, std::pair&lt;unsigned int const, Vote&gt;, std::_Select1st&lt;std::pair&lt;unsigned int const, Vote&gt; &gt;, std::less&lt;unsigned int&gt;, std::allocator&lt;std::pair&lt;unsigned int const, Vote&gt; &gt; &gt;::_M_insert_unique(this=0x407a59, __v=...) (/usr/include/c++/4.4/bits/stl_tree.h:1170)
  #2 0x40fb25 std::map&lt;unsigned int, Vote, std::less&lt;unsigned int&gt;, std::allocator&lt;std::pair&lt;unsigned int const, Vote&gt; &gt; &gt;::insert(this=0x407a59, __x=...) (/usr/include/c++/4.4/bits/stl_map.h:500)
  #3 0x40f06f VoteContainer::registerVote(this=0x407a51, inOrderId=1, inPermittedDrivers=..., inSeconds=32) (/home/user/workspace/src/merit_your_name/VoteContainer.cpp:81)
  </code></pre>
  
  <p>i suppose the reason of segfault is argument <code>__y=@0x758948f87d894905</code>. i have no idea why this is! at that moment m_votes map is empty. please, suggest me...</p>
  
  <p>As Matthieu M. says the most probable reason is uninitialized value <code>__y=@0x758948f87d894905</code>, but <code>__y</code> has type of <code>order_id_t</code> but not <code>Vote</code></p>
  
  <p>i've tried to rewrite code :</p>
  
  <pre><code>std::map&lt;int, int&gt; m_votes;
  </code></pre>
  
  <p>and this didn't solve my problem, therefore, the problem isn't in my types...</p>
  
  <p>here is the code invoking <code>registerVote()</code> method.</p>
  
  <pre><code>void OrderProcessor::processOrder(Order inOrder) {
      //test!!!
      driver_id_t driver_ids[] = {1,2};
      std::vector&lt;driver_id_t&gt; drivers(driver_ids, driver_ids + sizeof(driver_ids) / sizeof(driver_id_t) );
  
      m_vote_container-&gt;registerVote(inOrder.getId(), drivers, 32);
  
      for(size_t i = 0; i &lt; drivers.size(); i++) {
          std::cout &lt;&lt; "sending vote to " &lt;&lt; drivers[i] &lt;&lt; " driver. " &lt;&lt; std::endl;
          std::cout &lt;&lt; "send returns " &lt;&lt; Arch::send_to_socket_nonblock((*m_drivers_connections)[drivers[i]], "&lt;vote&gt;1&lt;/vote&gt;") &lt;&lt; std::endl;
      }
  
      sleep(32);
  
      Vote vote = m_vote_container-&gt;getVote(inOrder.getId());
      vote.getAppropriateDriverId(driver_id);
      m_vote_container-&gt;deleteVote(inOrder.getId());
  };
  </code></pre>
  
  <p>Yesterday,i found out there is problem not in my code! i've replaced std::map to other stl structures but the result was the same! i've deleted stl from that code and segfault was in Vote constructor, i've deleted this class and segfault was in other stl structures of my code! what is that? help me please.</p>
  
  <p>i've found out the reason of my problem, that isn't this code. problem was in my previous code. thank you all for participating this discussion.</p>