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 |
A program performs dynamic allocation outside the initialization phase.
For the purpose of this check, memory allocation is considered to be in the initialization phase if it takes place in a function f() specified with configuration file parameter DYN_INIT_FUNCTIONS, or in a function directly or transitively called by f().
| Class Name | Dynamic Allocation After Initialization | ||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Significance | style | ||||||||||||||||||||||||||||||||||||||||||
| Mnemonic | ALLOC.POSTINIT | ||||||||||||||||||||||||||||||||||||||||||
| Categories |
|
||||||||||||||||||||||||||||||||||||||||||
| Availability | Available for C and C++. |
||||||||||||||||||||||||||||||||||||||||||
| Enabling | Checks for this warning class are
disabled by default. To enable them, add the following WARNING_FILTER
rule to the project configuration file.
WARNING_FILTER += allow class="Dynamic Allocation After Initialization" |
#include <stdlib.h> char * disk_buff; char * network_buff; /* With factory settings, function name 'dyn_init' matches a * DYN_INIT_FUNCTIONS rule, so this function can directly or * transitively call allocator functions without triggering a 'Dynamic * Allocation After Initialization' warning */ void dyn_init(void){ disk_buff = malloc(1024); network_buff = malloc(2048); } int main(int argc, char *argv[]){ char *r; char rv = 0; /* starting process - do all dynamic allocation now */ dyn_init(); /* no more dynamic allocation from this point on */ /* ... */ r = malloc(5); /* 'Dynamic Allocation After Initialization' warning issued here */ /* ... */ if (r){ rv = 1; free(r); } return rv; }
Warnings of this class can be triggered by the following functions.
Only code reachable from a program entry point can trigger warnings for this class. CodeSonar will treat a function as a program entry point if it is specified with configuration file parameter PROGRAM_ENTRY_POINTS. The factory setting of this parameter instructs CodeSonar to treat main() and init() as entry points.
The following configuration file parameters affect checks for this warning class.
To report problems with this documentation, please visit https://support.codesecure.com/.