Skip to content

Latest commit

 

History

History
64 lines (51 loc) · 1.94 KB

c6388.md

File metadata and controls

64 lines (51 loc) · 1.94 KB
description title ms.date f1_keywords helpviewer_keywords ms.assetid
Learn more about: Warning C6388
Warning C6388
11/04/2016
C6388
INVALID_PARAM_VALUE_2
__WARNING_INVALID_PARAM_VALUE_2
C6388
667fe9cf-cc53-49f9-b6c0-6ee87c397568

Warning C6388

'argument' may not be 'value': this does not adhere to the specification for the function 'function-name': Lines: x, y

Remarks

This warning indicates that an unexpected value is being used in the specified context. This warning is typically reported for values passed as arguments to a function that doesn't expect it.

Code analysis name: INVALID_PARAM_VALUE_2

Example

The following code generates warning C6388 because DoSomething expects a null value but a potentially non-null value might be passed:

// C6388_warning.cpp
#include <string.h>
#include <malloc.h>
#include <sal.h>

void DoSomething( _Pre_ _Null_ void* pReserved );

void f()
{
    void* p = malloc( 10 );
    DoSomething( p );  // Warning C6388
    // code...
    free(p);
}

To correct this warning, use the following sample code:

// C6388_no_warning.cpp
#include <string.h>
#include <malloc.h>
#include <sal.h>

void DoSomething( _Pre_ _Null_ void* pReserved );
void f()
{
    void* p = malloc( 10 );
    if (!p)
    {
        DoSomething( p );
    }
    else
    {
        // code...
        free(p);
    }
}

The use of malloc and free has many pitfalls in terms of memory leaks and exceptions. To avoid these kinds of leaks and exception problems altogether, use the mechanisms that are provided by the C++ Standard Library (STL). These include shared_ptr, unique_ptr, and containers such as vector. For more information, see Smart pointers and C++ Standard Library.