Unicorn with delicious cookie
Nous utilisons des cookies pour améliorer votre expérience de navigation. En savoir plus
Accepter
to the top
>
>
>
Access Violation

Access Violation

12 Oct 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

S'abonner

Comments (0)

close comment form
close form

Remplissez le formulaire ci‑dessous en 2 étapes simples :

Vos coordonnées :

Étape 1
Félicitations ! Voici votre code promo !

Type de licence souhaité :

Étape 2
Team license
Enterprise licence
** En cliquant sur ce bouton, vous déclarez accepter notre politique de confidentialité
close form
Demandez des tarifs
Nouvelle licence
Renouvellement de licence
--Sélectionnez la devise--
USD
EUR
* En cliquant sur ce bouton, vous déclarez accepter notre politique de confidentialité

close form
La licence PVS‑Studio gratuit pour les spécialistes Microsoft MVP
close form
Pour obtenir la licence de votre projet open source, s’il vous plait rempliez ce formulaire
* En cliquant sur ce bouton, vous déclarez accepter notre politique de confidentialité

close form
I want to join the test
* En cliquant sur ce bouton, vous déclarez accepter notre politique de confidentialité

close form
check circle
Votre message a été envoyé.

Nous vous répondrons à


Si l'e-mail n'apparaît pas dans votre boîte de réception, recherchez-le dans l'un des dossiers suivants:

  • Promotion
  • Notifications
  • Spam