What Segmentation Fault Really Is

◀ Segmentation Fault▶ General Causes
Amazon The bane of most programmers is probably the classic bug “segmentation fault”. While it is often elusive and insidious, it is there for a reason and there are ways to avoid it.

Technically speaking, a program execution yields segmentation fault when the program violates segment structures by accessing an address it is not supposed to access in the runtime memory address space.
So how do we know which segments we are allowed to access and which we are not allowed to access?

Of course we do. Suppose we declare an array of 10 integers, our program should not go beyond 9 while accessing an element in the array. Sometimes a program changes the return address of a function call inadvertently or purposely (trying to pull off a buffer-overflow attack, for example) in which case it may get a segmentation fault because the function does not return to the place where it’s supposed to return.


In the next few chapters we will see some of the most common causes of a segmentation fault and discuss how to avoid them! Read on!
◀ Segmentation Fault▶ General Causes

fShare
Questions? Let me know!