-
November 20th, 2015, 07:53 AM
#1
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
-
November 20th, 2015, 08:30 AM
#2
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
-
November 20th, 2015, 08:38 AM
#3
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 )
-
November 20th, 2015, 09:03 AM
#4
Re: crash on map access
Originally Posted by pdk5
@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
-
November 20th, 2015, 09:07 AM
#5
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.
-
November 20th, 2015, 10:58 AM
#6
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, )
-
November 22nd, 2015, 12:49 PM
#7
Re: crash on map access
Originally Posted by pdk5
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.
-
November 23rd, 2015, 05:00 AM
#8
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|