RADE

C++ Source Checker

mkCheckSource Callback Checks

Testing source code in the CAA V5 environment
Technical Article

Abstract

This article describes the check relative to callbacks. This check is identified by BCBA.


Problematic

The callback mechanism is the way CAA V5 implements publish/subscribe between objects. This mechanism is implemented with method pointers. The user has to specify the type of the method by a cast of the address of the method pointer. If the cast does not meet the method signature (incorrect number of arguments), heap overwriting will happen at runtime, which is a serious problem leading to memory corruption.

4 ways of setting a callback are checked by the tool :

[Top]

Checks

Principle

For each occurrence of a callback set (each occurrence of AddAnalyseNotificationCB, AddCallback, AddTransition or Filter), the tool looks if the corresponding argument (ex : 3rd for AddAnalyseNotificationCB) is a method pointer. If it is, CSC looks in its symbol table for the implementation of this method. If the corresponding implementation does not have the good number of arguments (ex : 3 for AddAnalyseNotificationCB), the tool reports a BCBA error.

BCBA

BCBA stands for Bad CallBAck.

An error of type BCBA is reported when :

Example BCBA-1

Let's assume that the signature of the method OnMechanismSelectionChange of the class CATDeviceMoveScheduleDlg is :

class CATDeviceMoveScheduleDlg
{
  ...
  void OnMechanismSelectionChange( CATCommand * iFromClient, CATNotification * iEvtDat);
  ...
}

The following code will report a BCBA error :

CATDeviceMoveDcheduleDlg.cpp
...
AddAnalyseNotificationCB(_selection, _selection-> GetComboSelectNotification(), 
  (CATCommandMethod) &CATDeviceMoveScheduleDlg::OnMechanismSelectionChange, NULL);
...

To correct the error, modify the signature of  CATDeviceMoveScheduleDlg::OnMechanismSelectionChange like the following :

class CATDeviceMoveScheduleDlg
{
  ...
  void OnMechanismSelectionChange( 	CATCommand * iFromClient,
				CATNotification * iEvtDat,
				CATCommandClientData iUsefulData);
  ...
}

[Top]

Relative sections in setting files

No external parameter is taken into account for this check.

[Top]


In Short

C++ Source Checker can easily and quickly point bad usage of callbacks, preventing a very laborious runtime debug, preventing runtime abort and waste of time for the user.

[Top]


References

[1] The Callback Mechanism
[2] The Send/Receive Communication Protocol
[3] Implementing the Statechart Diagram
[Top]

History

Version: 1 [May 2001] Document created
[Top]

Copyright © 2000, Dassault Systèmes. All rights reserved.