Export (0) Print
Expand All
Expand Minimize
This topic has not yet been rated - Rate this topic

C6388

warning C6388: <argument> may not be <value>: this does not adhere to the specification for the function <function name>: Lines: x, y

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

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

#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:

#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);
    }
}

Note that the use of malloc and free have 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 Template Library (STL). These include shared_ptr, unique_ptr, and vector. For more information, see Smart Pointers (Modern C++) and Standard C++ Library Reference.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.