Warning C28196
The requirement is not satisfied. (The expression does not evaluate to true.)
This warning indicates that the function being analyzed has a __notnull
, __null
, __drv_valueIs
or similar annotation on an _Out_
parameter or the return value, but the value returned is inconsistent with that annotation.
Remarks
Annotations like __notnull
describe invariants about _Out_
parameters and return values, which serves both as documentation and as a sanity check for the author of the function. Warning C28196 indicates a mismatch between the annotations and the actual behavior of the function. The warning can be useful for discovering cases where a function might behave unexpectedly for certain input values. It's then up to the author to decide what the intended behavior of the function is and either adapt the annotations or the implementation accordingly.
Examples
The following function causes warning C28196 because it's annotated with _Ret_notnull_
even though some code paths return a null pointer.
#include <sal.h>
_Ret_notnull_
Item *get_item(_In_reads_(len) Item *items, size_t len, size_t index) {
if (index >= len) {
return nullptr;
}
return items + index;
}
To resolve this issue, refine the annotation to accurately reflect the function's behavior.
#include <sal.h>
_When_(index < len, _Ret_notnull_)
Item *get_item(_In_reads_(len) Item *items, size_t len, size_t index) {
if (index >= len) {
return nullptr;
}
return items + index;
}
See also
Annotating function parameters and return values
Specifying When and Where an Annotation Applies\