Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1035039
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T14:29:08+00:00 2026-05-16T14:29:08+00:00

i’ve used search but i didn’t find answer satisfying me… so.. this is chunk

  • 0

i’ve used search but i didn’t find answer satisfying me… so.. this is chunk of 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<driver_id_t> inPermittedDrivers, int inSeconds);
            Vote(const Vote & 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<DriverResponse> m_drivers_responses;
            std::vector<driver_id_t> m_permitted_drivers;
        };

class VoteContainer {
public:

    VoteContainer() {};
    virtual ~VoteContainer() {};

    void registerVote(order_id_t inOrderId, std::vector<driver_id_t> inPermittedDrivers, int inSeconds);

private:
    std::map<order_id_t, Vote> m_votes;
};

and how i use it:

//VoteContainer.cpp
void VoteContainer::registerVote(order_id_t inOrderId, std::vector<driver_id_t> inPermittedDrivers, int inSeconds) {
        m_votes.insert(std::make_pair(inOrderId,  Vote(inOrderId, inPermittedDrivers, inSeconds)));
    return;
};

i have segfault in regardless of what i do:

m_votes.insert(std::make_pair(inOrderId,  Vote(inOrderId, inPermittedDrivers, inSeconds)));

i’ve tried to use std::map::find(…) first, but i have same result. backtrace:

#0 0x41096a std::less<unsigned int>::operator() (this=0x407a59, __x=@0x7fffffff0b50, __y=@0x758948f87d894905) (/usr/include/c++/4.4/bits/stl_function.h:230)
#1 0x4105fb std::_Rb_tree<unsigned int, std::pair<unsigned int const, Vote>, std::_Select1st<std::pair<unsigned int const, Vote> >, std::less<unsigned int>, std::allocator<std::pair<unsigned int const, Vote> > >::_M_insert_unique(this=0x407a59, __v=...) (/usr/include/c++/4.4/bits/stl_tree.h:1170)
#2 0x40fb25 std::map<unsigned int, Vote, std::less<unsigned int>, std::allocator<std::pair<unsigned int const, Vote> > >::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)

i suppose the reason of segfault is argument __y=@0x758948f87d894905. i have no idea why this is! at that moment m_votes map is empty. please, suggest me…

As Matthieu M. says the most probable reason is uninitialized value __y=@0x758948f87d894905, but __y has type of order_id_t but not Vote

i’ve tried to rewrite code :

std::map<int, int> m_votes;

and this didn’t solve my problem, therefore, the problem isn’t in my types…

here is the code invoking registerVote() method.

void OrderProcessor::processOrder(Order inOrder) {
    //test!!!
    driver_id_t driver_ids[] = {1,2};
    std::vector<driver_id_t> drivers(driver_ids, driver_ids + sizeof(driver_ids) / sizeof(driver_id_t) );

    m_vote_container->registerVote(inOrder.getId(), drivers, 32);

    for(size_t i = 0; i < drivers.size(); i++) {
        std::cout << "sending vote to " << drivers[i] << " driver. " << std::endl;
        std::cout << "send returns " << Arch::send_to_socket_nonblock((*m_drivers_connections)[drivers[i]], "<vote>1</vote>") << std::endl;
    }

    sleep(32);

    Vote vote = m_vote_container->getVote(inOrder.getId());
    vote.getAppropriateDriverId(driver_id);
    m_vote_container->deleteVote(inOrder.getId());
};

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.

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T14:29:09+00:00Added an answer on May 16, 2026 at 2:29 pm

    From what I can see, I would venture that the really important code is missing.

    As noted: this=0x407a59, __x=@0x7fffffff0b50, __y=@0x758948f87d894905 is quite strange, the addresses are way too apart, so we can suppose that one of them (at least) is simply uninitialized. And for my own sanity I’ll suppose that your implementation of std::map is not buggy.

    My gut feeling would be to look for an uninitialized map, and therefore, and uninitialized VoteContainer object. Would you have some VoteContainer* that you forgot to allocate before invoking registerVote on it ?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This could be a duplicate question, but I have no idea what search terms
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
Seemingly simple, but I cannot find anything relevant on the web. What is the
I used javascript for loading a picture on my website depending on which small
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.