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.0p0 Hot Tips | CONFIDENTIAL | CodeSecure Inc |
A use of one of the following, declared in <stdlib.h> (C) / <cstdlib> (C++), when defined as a macro: malloc(), calloc(), realloc(), free().
These macros are disallowed by some coding standards.
If your libc implementation defines these as functions, uses will instead be reported as Use of <stdlib.h> Allocator/Deallocator warnings.
| Class Name | Use of <stdlib.h> Allocator/Deallocator Macro | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Significance | style | ||||||||||||||||||||||||||||||
| Mnemonic | BADMACRO.STDLIB_H_MEM | ||||||||||||||||||||||||||||||
| 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="Use of <stdlib.h> Allocator/Deallocator Macro" |
#include <cstdlib>
class Intpair {
public:
int a;
int b;
Intpair(int aval, int bval): a(aval),b(bval){}
int sum(){return a+b;}
};
int baduse(){
int s;
Intpair *i = (Intpair*)malloc(sizeof(Intpair)); // Warning issued here:
// - 'Use of <stdlib.h> Allocator/Deallocator Macro' if malloc() implemented as a macro
// - 'Use of <stdlib.h> Allocator/Deallocator' if malloc() implemented as a function
if (i==NULL) {return 0;}
i->a = 5;
i->b = 7;
s = i->sum();
free(i); // Warning issued here:
// - 'Use of <stdlib.h> Allocator/Deallocator Macro' if free() implemented as a macro
// - 'Use of <stdlib.h> Allocator/Deallocator' if free() implemented as a function
return s;
}
int gooduse(){ // OK: uses constructor and destructor instead of malloc/free.
Intpair *i = new Intpair(5,7);
int s = i->sum();
delete i;
return s;
}
This class is implemented using a BAD_MACRO_* rule set in the general template configuration file.
The following configuration file parameters affect checks for this warning class.