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 function that is supposed to use or release a resource is called with an argument that was previously allocated or used with a contradictory type.
| Warning Class Name | Notes |
|---|---|
| Type Mismatch | An argument was previously allocated or used with a contradictory type. |
| Pool Mismatch | A function is passed a pointer argument that should belong to the same heap as its heap handle argument but does not. |
| LocalLock on LMEM_FIXED
Memory LocalHandle on LMEM_FIXED Memory LocalUnlock on LMEM_FIXED Memory |
An attempt to lock, unlock, or acquire a handle for a local memory object that was allocated with LMEM_FIXED (and thus always has a lock count of 0). |
| GlobalLock on GMEM_FIXED Memory GlobalHandle on GMEM_FIXED Memory GlobalUnlock on GMEM_FIXED Memory |
An attempt to lock, unlock, or acquire a handle for a global memory object that was allocated with GMEM_FIXED (and thus always has a lock count of 0). |
CodeSonar performs checks for the following type mismatch warning classes.
Multiple warning classes share this mnemonic.
Checks for all these warning classes are enabled by default. To disable them all at once, add the following WARNING_FILTER rule to the project configuration file.
WARNING_FILTER += discard categories:ALLOC.TM
| Class Name | GlobalHandle on GMEM_FIXED Memory | |||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Significance | reliability | |||||||||||||||||||||
| Mnemonic | ALLOC.TM | |||||||||||||||||||||
| Categories |
|
|||||||||||||||||||||
| 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="GlobalHandle on GMEM_FIXED Memory" |
| Class Name | GlobalLock on GMEM_FIXED Memory | |||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Significance | reliability | |||||||||||||||||||||
| Mnemonic | ALLOC.TM | |||||||||||||||||||||
| Categories |
|
|||||||||||||||||||||
| 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="GlobalLock on GMEM_FIXED Memory" |
| Class Name | GlobalUnlock on GMEM_FIXED Memory | |||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Significance | reliability | |||||||||||||||||||||
| Mnemonic | ALLOC.TM | |||||||||||||||||||||
| Categories |
|
|||||||||||||||||||||
| 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="GlobalUnlock on GMEM_FIXED Memory" |
| Class Name | LocalHandle on LMEM_FIXED Memory | |||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Significance | reliability | |||||||||||||||||||||
| Mnemonic | ALLOC.TM | |||||||||||||||||||||
| Categories |
|
|||||||||||||||||||||
| 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="LocalHandle on LMEM_FIXED Memory" |
| Class Name | LocalLock on LMEM_FIXED Memory | |||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Significance | reliability | |||||||||||||||||||||
| Mnemonic | ALLOC.TM | |||||||||||||||||||||
| Categories |
|
|||||||||||||||||||||
| 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="LocalLock on LMEM_FIXED Memory" |
| Class Name | LocalUnlock on LMEM_FIXED Memory | |||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Significance | reliability | |||||||||||||||||||||
| Mnemonic | ALLOC.TM | |||||||||||||||||||||
| Categories |
|
|||||||||||||||||||||
| 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="LocalUnlock on LMEM_FIXED Memory" |
| Class Name | Pool Mismatch | |||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Significance | security | |||||||||||||||
| Mnemonic | ALLOC.TM | |||||||||||||||
| Categories |
|
|||||||||||||||
| 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="Pool Mismatch" |
| Class Name | Type Mismatch | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Significance | security | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Mnemonic | ALLOC.TM | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Categories |
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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="Type Mismatch" |
The following sections describe the Type Mismatch warning cases.
CodeSonar will issue a Type Mismatch warning when a checked function is called with an argument that was previously allocated or used with a contradictory type. This includes an attempt to free memory that was not allocated on the heap.
The checked function/argument pairs are divided into type families based on the required type of the argument. For example, fclose(FILE *stream) and feof(FILE *stream) are in the same type family because they both require a valid FILE* argument.
CodeSonar ships with library models that allow it to recognize a large number of functions that take multiple memory region arguments that should not overlap. If one of these functions is called with incompatible arguments, a warning will be issued.
If you have created a custom library model for some function f() in terms of one of these existing models, calls to f() will also be capable of triggering Pool Mismatch warnings.
CodeSonar has specific warning classes for attempts to call certain Win32 API functions on fixed local or global memory objects.
| Class Name | Triggering Function | Triggered If |
|---|---|---|
| LocalLock on LMEM_FIXED Memory | LocalLock() | The local memory object was originally allocated with the LMEM_FIXED flag. |
| LocalHandle on LMEM_FIXED Memory | LocalHandle() | |
| LocalUnlock on LMEM_FIXED Memory | LocalUnlock() | |
| GlobalLock on GMEM_FIXED Memory | GlobalLock() | The global memory object was originally allocated with the GMEM_FIXED flag. |
| GlobalHandle on GMEM_FIXED Memory | GlobalHandle() | |
| GlobalUnlock on GMEM_FIXED Memory | GlobalUnlock() |
#include <stdlib.h>
#include <stdio.h>
#include <dlfcn.h>
#include <windows.h>
void mix_malloc_delete()
{
char *p = (char*)malloc( 10 );
if( p )
delete[] p; /* "Type Mismatch" warning issued here */
}
void free_stack_variable()
{
char buf[10];
char *q = &buf[0];
free(q); /* "Type Mismatch" warning issued here */
}
void conflicting_types(void *p)
{
(void)ftell((FILE*)p);
(void)dlsym(p, "f"); /* "Type Mismatch" warning issued here -- p can't
* be both a FILE* and a dynamic shared object at
* the same time.
*/
}
void wrong_pool()
{
HANDLE pool1 = HeapCreate(0, 0, 1024*1024);
HANDLE pool2 = HeapCreate(0, 0, 1024*1024);
LPVOID ha = pool1 ? HeapAlloc(pool1, 0, 5) : NULL;
if( pool2 && ha )
(void)HeapFree(pool2, 0, ha); /* "Pool Mismatch" warning issued here; should have used pool1 */
exit(0);
}
void conflicting_types_win32(HANDLE h)
{
(void)GetThreadId(h);
(void)GetFileSize(h, 0); /* "Type Mismatch" warning issued here --
* h can't be both a thread and a window
* at the same time.
*/
exit(0);
}
void ghandle(void)
{
HGLOBAL x = GlobalAlloc(GMEM_FIXED, 16);
if( x )
{
(void)GlobalHandle(x); // GlobalHandle on GMEM_FIXED Memory issued here
(void)GlobalLock(x); // GlobalLock on GMEM_FIXED Memory issued here
(void)GlobalUnlock(x); // GlobalUnlock on GMEM_FIXED Memory issued here
}
exit(0);
}
void lhandle(void)
{
HLOCAL x = LocalAlloc(LMEM_FIXED, 16);
if( x )
{
(void)LocalHandle(x); // LocalHandle on LMEM_FIXED Memory issued here
(void)LocalLock(x); // LocalLock on LMEM_FIXED Memory issued here
(void)LocalUnlock(x); // LocalUnlock on LMEM_FIXED Memory issued here
}
exit(0);
}
The following configuration file parameters affect checks for this warning class.
To report problems with this documentation, please visit https://support.codesecure.com/.