Our website uses cookies to enhance your browsing experience.
Accept
to the top
>
>
>
Access Violation

Access Violation

Oct 12 2011

You may see messages containing "access violation" words when segmentation faults occur.

A segmentation fault (segfault in abbreviated form) is a software error occurring when a program tries to access memory addresses unavailable for writing or when a program tries to modify memory using an illegal method.

Segmentation is one of the approaches to memory management and protection in an operating system. In most systems it has been replaced by paged memory, but documentations traditionally use the term "Segmentation fault".

In UNIX-like operating systems, a process accessing invalid memory addresses receives a SIGSEGV signal. In Microsoft Windows, a process accessing invalid memory addresses raises an exception STATUS_ACCESS_VIOLATION and usually launches the Dr. Watson program which shows the user a window prompting to send the error report to Microsoft.

Memory access violation is most often caused by such errors in programs as array overruns or usage of a null pointer.

Let's examine a defect in a C++ program that can cause this type of errors. This error was found by our analyzer PVS-Studio in the Chromium project.

bool ChromeFrameNPAPI::Invoke(...)
{
  ChromeFrameNPAPI* plugin_instance =
    ChromeFrameInstanceFromNPObject(header);
  if (!plugin_instance &&
      (plugin_instance->automation_client_.get()))
    return false;
  ...  
}

This code should check the value of the 'plugin_instance' pointer and call the function if the pointer is not equal to zero. The error here is that the priority of the operator '!' is higher than that of the '&&' operator. As a result, the code behaves in an unexpected way. Arranging parentheses clarifies the point:

if ( (!plugin_instance) && 
     (plugin_instance->automation_client_.get()))
  return false;

It turns out that we will use a null pointer. Handling a null pointer will cause a segmentation fault and an exception will be thrown.

References

Popular related articles


Comments (0)

Next comments next comments
close comment form
close form

Fill out the form in 2 simple steps below:

Your contact information:

Step 1
Congratulations! This is your promo code!

Desired license type:

Step 2
Team license
Enterprise license
** By clicking this button you agree to our Privacy Policy statement
close form
Request our prices
New License
License Renewal
--Select currency--
USD
EUR
* By clicking this button you agree to our Privacy Policy statement

close form
Free PVS‑Studio license for Microsoft MVP specialists
* By clicking this button you agree to our Privacy Policy statement

close form
To get the licence for your open-source project, please fill out this form
* By clicking this button you agree to our Privacy Policy statement

close form
I am interested to try it on the platforms:
* By clicking this button you agree to our Privacy Policy statement

close form
check circle
Message submitted.

Your message has been sent. We will email you at


If you do not see the email in your inbox, please check if it is filtered to one of the following folders:

  • Promotion
  • Updates
  • Spam