CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    May 2015
    Posts
    500

    crash on map access

    Hi ,

    I have a static map,

    map<string, string> CPCC::m_mPDN2Imsi;

    and also within the CPPC class
    class CPPC
    {

    static map<string, string> m_mPDN2Imsi;
    }

    defined in CPPC.cpp

    and later in another file,

    It gets populated in another function and later on gdb

    (gdb) p CPPC::m_mPDN2Imsi
    $2 = std::map with 2 elements = {
    ["10.4.1.10"] = "111110000000002",
    ["10.4.1.11"] = "111110000000001"

    Then next line is
    map<string, string>::iterator iTerImsi = CPPC::m_mPDN2Imsi.find(sFramedIpAddr.AsText());
    string sImsi = iTerImsi->second;

    At accessing the imsi i.e "string sImsi = iTerImsi->second;", this crashes. I can see the key is present in the map, by the gdb debug earlier..

    Any help/hints much appreciated.

    ~p

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: crash on map access

    Please, edit your post adding code tags around code snippets! Otherwise it is very hard to read/understand what you did.
    And BTW, it is not a good practice using m_ prefix for class static members!
    Victor Nijegorodov

  3. #3
    Join Date
    May 2015
    Posts
    500

    Re: crash on map access

    @Victor, I have put hardly 2/3 lines of code. SO you can assume it as pseudocode.
    I may not be folowing coding standards, as of now, but will do once the code works.

    It will be great help, if you can spot any issues in the logic, than semantics of the code.
    (Being a c++ newbie, I will try my level best , but coming from c background it is bit hard )

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: crash on map access

    Quote Originally Posted by pdk5 View Post
    @Victor, I have put hardly 2/3 lines of code. SO you can assume it as pseudocode.
    I may not be folowing coding standards, as of now, but will do once the code works.

    It will be great help, if you can spot any issues in the logic, than semantics of the code.
    (Being a c++ newbie, I will try my level best , but coming from c background it is bit hard )
    Sorry, but I cannot see neither any "logic" nor "semantics" in your post.
    And note that it is your code that crashes! So the best way be to create a very small test project that reproduces your problem and post it to the forum, so would be able to debug/test it to understand the reason...
    Victor Nijegorodov

  5. #5
    Join Date
    May 2015
    Posts
    500

    Re: crash on map access

    ok thanks for your input, sorry if you cannot see it.
    Last edited by pdk5; November 20th, 2015 at 10:59 AM.

  6. #6
    Join Date
    May 2015
    Posts
    500

    Re: crash on map access

    @Victor thanks for feedback.

    Btw it was mistake from my side, that there are quite a few ways the IP address is stored in our legacy code..and it was wrong format of the ip address i.e causing this issue. Now corrected and works fine.

    It is bit difficult with our setup, to debug. Im working for small startup without much resources , so our debug setup is bit complicated (that too for a bad c++ programmer like me, )

  7. #7
    Join Date
    Jun 2015
    Posts
    208

    Re: crash on map access

    Quote Originally Posted by pdk5 View Post
    I have a static map,
    In an earlier reply to you here,

    http://forums.codeguru.com/showthrea...atic-map-table

    I gave a link to another thread where I've posted a complete implementation of a simple record database. It uses std::unordered_set (or alternatively std::set).

    It would be very easy to adapt using strings as keys and values.
    Last edited by tiliavirga; November 23rd, 2015 at 04:01 AM.

  8. #8
    Join Date
    May 2015
    Posts
    500

    Re: crash on map access

    @tiliavirga: Thanks a lot, very helpful

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured