Ignore SIGSEGV and continue execution [duplicate]











up vote
0
down vote

favorite













This question already has an answer here:




  • Why can't I ignore SIGSEGV signal?

    5 answers




I have a folder full of images that contain some metadata in the pixels that I'm trying to extract with my program. The program loops through each file, extracting the data. Problem is that some of the images are corrupted, and trying to extract data from them results in a segmentation fault.



Is there any way to catch this SIGSEGV signal and use it to ignore the current corrupted image and continue to the next noe?



try-catch will not help as this is a signal, not exception.



int Status::ExtractImageMetaData(cv::Mat src_in, int Index)
{
unsigned char *Image = (unsigned char *)(src_in.data);
unsigned char *StructByte = (unsigned char*) &ImageMetaData[Index];

uint32_t MetaOffset = (src_in.total() * src_in.elemSize()) - sizeof(ImageMetaData_t);


for(unsigned int i = 0; i < sizeof(ImageMetaData_t); i++)
{
StructByte[i] = Image[i + MetaOffset]; // SEGMENTATION FAULT HERE!

}
}





int main(int argc, char const *argv)
{

if (imagePath == NULL){
imagePath = "/Pictures/metadataExtractionTest/sqlTest/";
}


// Iterate over all files in the "imagePath"
for (const auto & p : fs::directory_iterator(imagePath)){

string FullImageDir = p.path();
Mat Img = imread(FullImageDir.c_str());

int MetaStatus = SystemStatus.ExtractImageMetaData(Img, 0);


printf("donen");

}


return 0;

}









share|improve this question















marked as duplicate by Raedwald, YSC c++
Users with the  c++ badge can single-handedly close c++ questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 8 at 12:24


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.











  • 2




    You shouldn't catch SIGSEGV. You should prevent it. If you have out of bounds array access, then check array size before you access it. Check for null as well.
    – Yksisarvinen
    Nov 7 at 9:37








  • 1




    Suggestions to cope with a segfault notwithstanding I must second @Yksisarvinen: The segfault probably comes because you blindly accept data from the files without checking it. Properly vetting the data for plausibility and specfication and implementation limits will (1) Probably allow you to tolerate some file corruption and still extract some image or meta data, and (2) make your program more secure. The last one is more important if you run it on third-party sources or even distribute it: Because maliciously crafted files could actually attack your computer.
    – Peter A. Schneider
    Nov 7 at 12:37








  • 1




    OK guys. Followed your advice and checked for columns and rows in the input images before trying to extract metadata from them. That did the trick
    – eirikaso
    Nov 7 at 12:42










  • Always nice to find the 'right' solution - i.e. one that fixes the underlying and properly understood problem.
    – Rags
    Nov 7 at 13:15















up vote
0
down vote

favorite













This question already has an answer here:




  • Why can't I ignore SIGSEGV signal?

    5 answers




I have a folder full of images that contain some metadata in the pixels that I'm trying to extract with my program. The program loops through each file, extracting the data. Problem is that some of the images are corrupted, and trying to extract data from them results in a segmentation fault.



Is there any way to catch this SIGSEGV signal and use it to ignore the current corrupted image and continue to the next noe?



try-catch will not help as this is a signal, not exception.



int Status::ExtractImageMetaData(cv::Mat src_in, int Index)
{
unsigned char *Image = (unsigned char *)(src_in.data);
unsigned char *StructByte = (unsigned char*) &ImageMetaData[Index];

uint32_t MetaOffset = (src_in.total() * src_in.elemSize()) - sizeof(ImageMetaData_t);


for(unsigned int i = 0; i < sizeof(ImageMetaData_t); i++)
{
StructByte[i] = Image[i + MetaOffset]; // SEGMENTATION FAULT HERE!

}
}





int main(int argc, char const *argv)
{

if (imagePath == NULL){
imagePath = "/Pictures/metadataExtractionTest/sqlTest/";
}


// Iterate over all files in the "imagePath"
for (const auto & p : fs::directory_iterator(imagePath)){

string FullImageDir = p.path();
Mat Img = imread(FullImageDir.c_str());

int MetaStatus = SystemStatus.ExtractImageMetaData(Img, 0);


printf("donen");

}


return 0;

}









share|improve this question















marked as duplicate by Raedwald, YSC c++
Users with the  c++ badge can single-handedly close c++ questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 8 at 12:24


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.











  • 2




    You shouldn't catch SIGSEGV. You should prevent it. If you have out of bounds array access, then check array size before you access it. Check for null as well.
    – Yksisarvinen
    Nov 7 at 9:37








  • 1




    Suggestions to cope with a segfault notwithstanding I must second @Yksisarvinen: The segfault probably comes because you blindly accept data from the files without checking it. Properly vetting the data for plausibility and specfication and implementation limits will (1) Probably allow you to tolerate some file corruption and still extract some image or meta data, and (2) make your program more secure. The last one is more important if you run it on third-party sources or even distribute it: Because maliciously crafted files could actually attack your computer.
    – Peter A. Schneider
    Nov 7 at 12:37








  • 1




    OK guys. Followed your advice and checked for columns and rows in the input images before trying to extract metadata from them. That did the trick
    – eirikaso
    Nov 7 at 12:42










  • Always nice to find the 'right' solution - i.e. one that fixes the underlying and properly understood problem.
    – Rags
    Nov 7 at 13:15













up vote
0
down vote

favorite









up vote
0
down vote

favorite












This question already has an answer here:




  • Why can't I ignore SIGSEGV signal?

    5 answers




I have a folder full of images that contain some metadata in the pixels that I'm trying to extract with my program. The program loops through each file, extracting the data. Problem is that some of the images are corrupted, and trying to extract data from them results in a segmentation fault.



Is there any way to catch this SIGSEGV signal and use it to ignore the current corrupted image and continue to the next noe?



try-catch will not help as this is a signal, not exception.



int Status::ExtractImageMetaData(cv::Mat src_in, int Index)
{
unsigned char *Image = (unsigned char *)(src_in.data);
unsigned char *StructByte = (unsigned char*) &ImageMetaData[Index];

uint32_t MetaOffset = (src_in.total() * src_in.elemSize()) - sizeof(ImageMetaData_t);


for(unsigned int i = 0; i < sizeof(ImageMetaData_t); i++)
{
StructByte[i] = Image[i + MetaOffset]; // SEGMENTATION FAULT HERE!

}
}





int main(int argc, char const *argv)
{

if (imagePath == NULL){
imagePath = "/Pictures/metadataExtractionTest/sqlTest/";
}


// Iterate over all files in the "imagePath"
for (const auto & p : fs::directory_iterator(imagePath)){

string FullImageDir = p.path();
Mat Img = imread(FullImageDir.c_str());

int MetaStatus = SystemStatus.ExtractImageMetaData(Img, 0);


printf("donen");

}


return 0;

}









share|improve this question
















This question already has an answer here:




  • Why can't I ignore SIGSEGV signal?

    5 answers




I have a folder full of images that contain some metadata in the pixels that I'm trying to extract with my program. The program loops through each file, extracting the data. Problem is that some of the images are corrupted, and trying to extract data from them results in a segmentation fault.



Is there any way to catch this SIGSEGV signal and use it to ignore the current corrupted image and continue to the next noe?



try-catch will not help as this is a signal, not exception.



int Status::ExtractImageMetaData(cv::Mat src_in, int Index)
{
unsigned char *Image = (unsigned char *)(src_in.data);
unsigned char *StructByte = (unsigned char*) &ImageMetaData[Index];

uint32_t MetaOffset = (src_in.total() * src_in.elemSize()) - sizeof(ImageMetaData_t);


for(unsigned int i = 0; i < sizeof(ImageMetaData_t); i++)
{
StructByte[i] = Image[i + MetaOffset]; // SEGMENTATION FAULT HERE!

}
}





int main(int argc, char const *argv)
{

if (imagePath == NULL){
imagePath = "/Pictures/metadataExtractionTest/sqlTest/";
}


// Iterate over all files in the "imagePath"
for (const auto & p : fs::directory_iterator(imagePath)){

string FullImageDir = p.path();
Mat Img = imread(FullImageDir.c_str());

int MetaStatus = SystemStatus.ExtractImageMetaData(Img, 0);


printf("donen");

}


return 0;

}




This question already has an answer here:




  • Why can't I ignore SIGSEGV signal?

    5 answers








c++






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 7 at 9:34

























asked Nov 7 at 9:24









eirikaso

267




267




marked as duplicate by Raedwald, YSC c++
Users with the  c++ badge can single-handedly close c++ questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 8 at 12:24


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






marked as duplicate by Raedwald, YSC c++
Users with the  c++ badge can single-handedly close c++ questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 8 at 12:24


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.










  • 2




    You shouldn't catch SIGSEGV. You should prevent it. If you have out of bounds array access, then check array size before you access it. Check for null as well.
    – Yksisarvinen
    Nov 7 at 9:37








  • 1




    Suggestions to cope with a segfault notwithstanding I must second @Yksisarvinen: The segfault probably comes because you blindly accept data from the files without checking it. Properly vetting the data for plausibility and specfication and implementation limits will (1) Probably allow you to tolerate some file corruption and still extract some image or meta data, and (2) make your program more secure. The last one is more important if you run it on third-party sources or even distribute it: Because maliciously crafted files could actually attack your computer.
    – Peter A. Schneider
    Nov 7 at 12:37








  • 1




    OK guys. Followed your advice and checked for columns and rows in the input images before trying to extract metadata from them. That did the trick
    – eirikaso
    Nov 7 at 12:42










  • Always nice to find the 'right' solution - i.e. one that fixes the underlying and properly understood problem.
    – Rags
    Nov 7 at 13:15














  • 2




    You shouldn't catch SIGSEGV. You should prevent it. If you have out of bounds array access, then check array size before you access it. Check for null as well.
    – Yksisarvinen
    Nov 7 at 9:37








  • 1




    Suggestions to cope with a segfault notwithstanding I must second @Yksisarvinen: The segfault probably comes because you blindly accept data from the files without checking it. Properly vetting the data for plausibility and specfication and implementation limits will (1) Probably allow you to tolerate some file corruption and still extract some image or meta data, and (2) make your program more secure. The last one is more important if you run it on third-party sources or even distribute it: Because maliciously crafted files could actually attack your computer.
    – Peter A. Schneider
    Nov 7 at 12:37








  • 1




    OK guys. Followed your advice and checked for columns and rows in the input images before trying to extract metadata from them. That did the trick
    – eirikaso
    Nov 7 at 12:42










  • Always nice to find the 'right' solution - i.e. one that fixes the underlying and properly understood problem.
    – Rags
    Nov 7 at 13:15








2




2




You shouldn't catch SIGSEGV. You should prevent it. If you have out of bounds array access, then check array size before you access it. Check for null as well.
– Yksisarvinen
Nov 7 at 9:37






You shouldn't catch SIGSEGV. You should prevent it. If you have out of bounds array access, then check array size before you access it. Check for null as well.
– Yksisarvinen
Nov 7 at 9:37






1




1




Suggestions to cope with a segfault notwithstanding I must second @Yksisarvinen: The segfault probably comes because you blindly accept data from the files without checking it. Properly vetting the data for plausibility and specfication and implementation limits will (1) Probably allow you to tolerate some file corruption and still extract some image or meta data, and (2) make your program more secure. The last one is more important if you run it on third-party sources or even distribute it: Because maliciously crafted files could actually attack your computer.
– Peter A. Schneider
Nov 7 at 12:37






Suggestions to cope with a segfault notwithstanding I must second @Yksisarvinen: The segfault probably comes because you blindly accept data from the files without checking it. Properly vetting the data for plausibility and specfication and implementation limits will (1) Probably allow you to tolerate some file corruption and still extract some image or meta data, and (2) make your program more secure. The last one is more important if you run it on third-party sources or even distribute it: Because maliciously crafted files could actually attack your computer.
– Peter A. Schneider
Nov 7 at 12:37






1




1




OK guys. Followed your advice and checked for columns and rows in the input images before trying to extract metadata from them. That did the trick
– eirikaso
Nov 7 at 12:42




OK guys. Followed your advice and checked for columns and rows in the input images before trying to extract metadata from them. That did the trick
– eirikaso
Nov 7 at 12:42












Always nice to find the 'right' solution - i.e. one that fixes the underlying and properly understood problem.
– Rags
Nov 7 at 13:15




Always nice to find the 'right' solution - i.e. one that fixes the underlying and properly understood problem.
– Rags
Nov 7 at 13:15












3 Answers
3






active

oldest

votes

















up vote
2
down vote













An alternative solution that might be worth looking into: (This assumes you are on Linux or some other Unix variant)



Before processing each image, fork the process into two, one parent and one child process (which will otherwise be identical, look at the man page for fork(2)). Let the child do the risky stuff that might crash while the parent waits for it to terminate. If the child crashes, the parent can detect this and is still in a good state, so it can move on to the next image. If the child succeeds, you will need a way to transfer the result from the child to the parent, perhaps by using a pipe to send data. By opening the pipe before the fork call, both processes can connect using the same pipe.



As has already been suggested, fixing the crashes is probably the best solution, but sometimes that is not possible and you have to get "creative" instead.






share|improve this answer





















  • That is a very bad idea! A segfault is the lucky result, if you write "somewhere" into the memory. If your wrong memory access is going to a memory address which is allowed but not intended, everything can happen. In fact the code is broken by design. "Risky" means "running wrong code" and accept "everything can happen" is not a solution at all!
    – Klaus
    Nov 7 at 11:56


















up vote
1
down vote













Edited: SIGSEGV can't be caught as an exception with a try-catch block.



This page : Catch SIGSEV addresses the question.






share|improve this answer



















  • 4




    SIGSEGV is not an exception, it's a signal. try/catch won't help.
    – Quentin
    Nov 7 at 9:29










  • Already tried try-catch yes. Didn't work
    – eirikaso
    Nov 7 at 9:30










  • Fair point - been a while since I used Linux. Will consider.
    – Rags
    Nov 7 at 9:31


















up vote
0
down vote













You never should "Ignore SIGSEGV and continue execution" at all.



If your program writes per accident to some unknown memory address, the result is undefined. If your hardware detects the access to a unallowed memory region, you have luck! The bad case is that you access memory without getting a segfault. But after the access your memory is corrupted. So you can not rely on your code and the execution.



I believe the only thing you can do: Write correct code! This means: Check out of bounds access, maybe simply use containers from STL and use checked access like std::vector::at.



Accepting that a program can write to every memory location is not a solution because a segfault is not the guaranteed result.






share|improve this answer




























    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    2
    down vote













    An alternative solution that might be worth looking into: (This assumes you are on Linux or some other Unix variant)



    Before processing each image, fork the process into two, one parent and one child process (which will otherwise be identical, look at the man page for fork(2)). Let the child do the risky stuff that might crash while the parent waits for it to terminate. If the child crashes, the parent can detect this and is still in a good state, so it can move on to the next image. If the child succeeds, you will need a way to transfer the result from the child to the parent, perhaps by using a pipe to send data. By opening the pipe before the fork call, both processes can connect using the same pipe.



    As has already been suggested, fixing the crashes is probably the best solution, but sometimes that is not possible and you have to get "creative" instead.






    share|improve this answer





















    • That is a very bad idea! A segfault is the lucky result, if you write "somewhere" into the memory. If your wrong memory access is going to a memory address which is allowed but not intended, everything can happen. In fact the code is broken by design. "Risky" means "running wrong code" and accept "everything can happen" is not a solution at all!
      – Klaus
      Nov 7 at 11:56















    up vote
    2
    down vote













    An alternative solution that might be worth looking into: (This assumes you are on Linux or some other Unix variant)



    Before processing each image, fork the process into two, one parent and one child process (which will otherwise be identical, look at the man page for fork(2)). Let the child do the risky stuff that might crash while the parent waits for it to terminate. If the child crashes, the parent can detect this and is still in a good state, so it can move on to the next image. If the child succeeds, you will need a way to transfer the result from the child to the parent, perhaps by using a pipe to send data. By opening the pipe before the fork call, both processes can connect using the same pipe.



    As has already been suggested, fixing the crashes is probably the best solution, but sometimes that is not possible and you have to get "creative" instead.






    share|improve this answer





















    • That is a very bad idea! A segfault is the lucky result, if you write "somewhere" into the memory. If your wrong memory access is going to a memory address which is allowed but not intended, everything can happen. In fact the code is broken by design. "Risky" means "running wrong code" and accept "everything can happen" is not a solution at all!
      – Klaus
      Nov 7 at 11:56













    up vote
    2
    down vote










    up vote
    2
    down vote









    An alternative solution that might be worth looking into: (This assumes you are on Linux or some other Unix variant)



    Before processing each image, fork the process into two, one parent and one child process (which will otherwise be identical, look at the man page for fork(2)). Let the child do the risky stuff that might crash while the parent waits for it to terminate. If the child crashes, the parent can detect this and is still in a good state, so it can move on to the next image. If the child succeeds, you will need a way to transfer the result from the child to the parent, perhaps by using a pipe to send data. By opening the pipe before the fork call, both processes can connect using the same pipe.



    As has already been suggested, fixing the crashes is probably the best solution, but sometimes that is not possible and you have to get "creative" instead.






    share|improve this answer












    An alternative solution that might be worth looking into: (This assumes you are on Linux or some other Unix variant)



    Before processing each image, fork the process into two, one parent and one child process (which will otherwise be identical, look at the man page for fork(2)). Let the child do the risky stuff that might crash while the parent waits for it to terminate. If the child crashes, the parent can detect this and is still in a good state, so it can move on to the next image. If the child succeeds, you will need a way to transfer the result from the child to the parent, perhaps by using a pipe to send data. By opening the pipe before the fork call, both processes can connect using the same pipe.



    As has already been suggested, fixing the crashes is probably the best solution, but sometimes that is not possible and you have to get "creative" instead.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 7 at 11:39









    Johnny Johansson

    1956




    1956












    • That is a very bad idea! A segfault is the lucky result, if you write "somewhere" into the memory. If your wrong memory access is going to a memory address which is allowed but not intended, everything can happen. In fact the code is broken by design. "Risky" means "running wrong code" and accept "everything can happen" is not a solution at all!
      – Klaus
      Nov 7 at 11:56


















    • That is a very bad idea! A segfault is the lucky result, if you write "somewhere" into the memory. If your wrong memory access is going to a memory address which is allowed but not intended, everything can happen. In fact the code is broken by design. "Risky" means "running wrong code" and accept "everything can happen" is not a solution at all!
      – Klaus
      Nov 7 at 11:56
















    That is a very bad idea! A segfault is the lucky result, if you write "somewhere" into the memory. If your wrong memory access is going to a memory address which is allowed but not intended, everything can happen. In fact the code is broken by design. "Risky" means "running wrong code" and accept "everything can happen" is not a solution at all!
    – Klaus
    Nov 7 at 11:56




    That is a very bad idea! A segfault is the lucky result, if you write "somewhere" into the memory. If your wrong memory access is going to a memory address which is allowed but not intended, everything can happen. In fact the code is broken by design. "Risky" means "running wrong code" and accept "everything can happen" is not a solution at all!
    – Klaus
    Nov 7 at 11:56












    up vote
    1
    down vote













    Edited: SIGSEGV can't be caught as an exception with a try-catch block.



    This page : Catch SIGSEV addresses the question.






    share|improve this answer



















    • 4




      SIGSEGV is not an exception, it's a signal. try/catch won't help.
      – Quentin
      Nov 7 at 9:29










    • Already tried try-catch yes. Didn't work
      – eirikaso
      Nov 7 at 9:30










    • Fair point - been a while since I used Linux. Will consider.
      – Rags
      Nov 7 at 9:31















    up vote
    1
    down vote













    Edited: SIGSEGV can't be caught as an exception with a try-catch block.



    This page : Catch SIGSEV addresses the question.






    share|improve this answer



















    • 4




      SIGSEGV is not an exception, it's a signal. try/catch won't help.
      – Quentin
      Nov 7 at 9:29










    • Already tried try-catch yes. Didn't work
      – eirikaso
      Nov 7 at 9:30










    • Fair point - been a while since I used Linux. Will consider.
      – Rags
      Nov 7 at 9:31













    up vote
    1
    down vote










    up vote
    1
    down vote









    Edited: SIGSEGV can't be caught as an exception with a try-catch block.



    This page : Catch SIGSEV addresses the question.






    share|improve this answer














    Edited: SIGSEGV can't be caught as an exception with a try-catch block.



    This page : Catch SIGSEV addresses the question.







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Nov 7 at 9:33

























    answered Nov 7 at 9:28









    Rags

    30617




    30617








    • 4




      SIGSEGV is not an exception, it's a signal. try/catch won't help.
      – Quentin
      Nov 7 at 9:29










    • Already tried try-catch yes. Didn't work
      – eirikaso
      Nov 7 at 9:30










    • Fair point - been a while since I used Linux. Will consider.
      – Rags
      Nov 7 at 9:31














    • 4




      SIGSEGV is not an exception, it's a signal. try/catch won't help.
      – Quentin
      Nov 7 at 9:29










    • Already tried try-catch yes. Didn't work
      – eirikaso
      Nov 7 at 9:30










    • Fair point - been a while since I used Linux. Will consider.
      – Rags
      Nov 7 at 9:31








    4




    4




    SIGSEGV is not an exception, it's a signal. try/catch won't help.
    – Quentin
    Nov 7 at 9:29




    SIGSEGV is not an exception, it's a signal. try/catch won't help.
    – Quentin
    Nov 7 at 9:29












    Already tried try-catch yes. Didn't work
    – eirikaso
    Nov 7 at 9:30




    Already tried try-catch yes. Didn't work
    – eirikaso
    Nov 7 at 9:30












    Fair point - been a while since I used Linux. Will consider.
    – Rags
    Nov 7 at 9:31




    Fair point - been a while since I used Linux. Will consider.
    – Rags
    Nov 7 at 9:31










    up vote
    0
    down vote













    You never should "Ignore SIGSEGV and continue execution" at all.



    If your program writes per accident to some unknown memory address, the result is undefined. If your hardware detects the access to a unallowed memory region, you have luck! The bad case is that you access memory without getting a segfault. But after the access your memory is corrupted. So you can not rely on your code and the execution.



    I believe the only thing you can do: Write correct code! This means: Check out of bounds access, maybe simply use containers from STL and use checked access like std::vector::at.



    Accepting that a program can write to every memory location is not a solution because a segfault is not the guaranteed result.






    share|improve this answer

























      up vote
      0
      down vote













      You never should "Ignore SIGSEGV and continue execution" at all.



      If your program writes per accident to some unknown memory address, the result is undefined. If your hardware detects the access to a unallowed memory region, you have luck! The bad case is that you access memory without getting a segfault. But after the access your memory is corrupted. So you can not rely on your code and the execution.



      I believe the only thing you can do: Write correct code! This means: Check out of bounds access, maybe simply use containers from STL and use checked access like std::vector::at.



      Accepting that a program can write to every memory location is not a solution because a segfault is not the guaranteed result.






      share|improve this answer























        up vote
        0
        down vote










        up vote
        0
        down vote









        You never should "Ignore SIGSEGV and continue execution" at all.



        If your program writes per accident to some unknown memory address, the result is undefined. If your hardware detects the access to a unallowed memory region, you have luck! The bad case is that you access memory without getting a segfault. But after the access your memory is corrupted. So you can not rely on your code and the execution.



        I believe the only thing you can do: Write correct code! This means: Check out of bounds access, maybe simply use containers from STL and use checked access like std::vector::at.



        Accepting that a program can write to every memory location is not a solution because a segfault is not the guaranteed result.






        share|improve this answer












        You never should "Ignore SIGSEGV and continue execution" at all.



        If your program writes per accident to some unknown memory address, the result is undefined. If your hardware detects the access to a unallowed memory region, you have luck! The bad case is that you access memory without getting a segfault. But after the access your memory is corrupted. So you can not rely on your code and the execution.



        I believe the only thing you can do: Write correct code! This means: Check out of bounds access, maybe simply use containers from STL and use checked access like std::vector::at.



        Accepting that a program can write to every memory location is not a solution because a segfault is not the guaranteed result.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 7 at 12:02









        Klaus

        10.3k12557




        10.3k12557















            這個網誌中的熱門文章

            Xamarin.form Move up view when keyboard appear

            Post-Redirect-Get with Spring WebFlux and Thymeleaf

            Anylogic : not able to use stopDelay()