JavaScript is not currently enabled, but is required for full CodeSonar manual search and browse functionality.

If you are viewing this file in your hub's Web GUI, enable JavaScript in your browser: you will also need it for GUI functionality.

If you opened this file directly from disk, your browser may be directly suppressing JavaScript functionality: certain browsers perform this suppression on local files (but not files delivered by web servers) for security reasons.

CodeSonar® 9.2p0 CONFIDENTIAL CodeSecure Inc
C and C++
Binaries


LANG.STRUCT.RPL : Return Pointer to Local

Summary

A procedure returns a pointer to one of its local variables.

Properties

Class Name Return Pointer to Local
Significance security
Mnemonic LANG.STRUCT.RPL
Categories
MisraC2025 MisraC2025:18.6 The address of an object with automatic or thread-local storage shall not be copied to another object that persists after the first object has ceased to exist
MisraC2023 MisraC2023:18.6 The address of an object with automatic or thread-local storage shall not be copied to another object that persists after the first object has ceased to exist
Misra2012 Misra2012:18.6 The address of an object with automatic or thread-local storage shall not be copied to another object that persists after the first object has ceased to exist
AUTOSARC++14 AUTOSARC++14:M7-5-1 A function shall not return a reference or a pointer to an automatic variable (including parameters), defined within the function.
MisraC++2008 MisraC++2008:7-5-1 A function shall not return a reference or a pointer to an automatic variable (including parameters), defined within the function.
MisraC++2023 MisraC++2023:6.8.2 A function must not return a reference or a pointer to a local variable with automatic storage duration
CWE CWE:562 Return of Stack Variable Address
TS17961 TS17961:5.14-nullref Dereferencing an out-of-domain pointer
CERT-C CERT-C:DCL30-C Declare objects with appropriate storage durations
CERT-CPP CERT-CPP:EXP53-CPP Do not read uninitialized memory
JSF++ JSF++:70.1 An object shall not be improperly used before its lifetime begins or after its lifetime ends.
  JSF++:111 A function shall not return a pointer or reference to a non-static local object.
  JSF++:173 The address of an object with automatic storage shall not be assigned to an object which persists after the object has ceased to exist.
Availability Available for C and C++.
Enabling Checks for this warning class are enabled by default. To disable them, add the following WARNING_FILTER rule to the project configuration file.
WARNING_FILTER += discard class="Return Pointer to Local"

Example

int * lang_struct_rpl(void){
    int j = 7;
    return &j; /* 'Return Pointer To Local' warning issued here */
}

Relevant Configuration File Parameters

The following configuration file parameters affect checks for this warning class.

 

To report problems with this documentation, please visit https://support.codesecure.com/.