AttributeNonNull

From RAD Studio
Jump to: navigation, search

Go Up to C++ Audits

Description

Checks for null pointers passed as arguments to a function whose arguments are marked with the nonnull attribute.

To support the AttributeNonNull audit, you can use the nonnull attribute in function declarations:

 __attribute__((nonnull(arg_number, ...)))

Here arg_number, ... denotes numbers of arguments, which should not pass null pointers. If no arg_number is specified, all pointer arguments are treated as nonnull.

For example, the declaration:

 void * my_copy (void *destination, const void *source, int length)
            __attribute__((nonnull (1, 2)));

defines that, in calls to my_copy, the destination and source arguments should be non-NULL. If the AttributeNonNull audit determines that a null pointer is passed in the destination or source arguments, then the AttributeNonNull audit generates this violation in my_copy.

Note: The nonnull attribute is supported only in C++ audits and is ignored by the C++Builder compiler.


See Also