lilzz
Posts: 411
Joined: Sat Nov 30, 2013 5:27 pm

segmentation fault when debugging

Tue Dec 08, 2015 10:55 am

Code: Select all

 for (int i = 0; i < n_tiles; ++i)
    {
      for (const auto &p : tile_nets_idx[i])
      {
	extend(tile_nets[i], net_names[p.first], p.second);
      }
      
    }
Original code is as above. It runs fine. And I like to find out the values for p.first, p.second, net_names[p.first] so I modify the code as followed

Code: Select all

for (int i = 0; i < n_tiles; ++i)
    {
      for (const auto &p : tile_nets_idx[i])
      {
	extend(tile_nets[i], net_names[p.first], p.second);
        *logs << "p.first " << p.first << "...\n";
	*logs << "p.second " << p.second << "...\n";
	*logs << "net_names[p.first]" << net_names[p.first] << "...\n";
      }  
    }
When I step to the first *logs of p.first, it causes a segmentation fault.

what's the issue here? My original code runs fine.

User avatar
AndyD
Posts: 2334
Joined: Sat Jan 21, 2012 8:13 am
Location: Melbourne, Australia
Contact: Website

Re: segmentation fault when debugging

Tue Dec 08, 2015 11:23 am

You haven't shown us what "logs" is. It appears to be a pointer to an std::ostream object. Is that correct? Is it valid and not null? My initial guess is that "logs == nullptr".

lilzz
Posts: 411
Joined: Sat Nov 30, 2013 5:27 pm

Re: segmentation fault when debugging

Tue Dec 08, 2015 6:30 pm

OK, I solved by using std::cout instead

Return to “C/C++”