Warning C28159

Consider using *function_name_1* instead of *function_name_2*. Reason: reason

This warning occurs when you use a function that is semantically equivalent to an alternative, preferred function call.

Remarks

C28159 is a general warning message; the annotation __drv_preferredFunction was used (possibly with a conditional __drv_when() annotation) to flag a bad coding practice.

Code analysis name: USE_OTHER_FUNCTION

Example

The following code example generates this warning. This issue is due to the use of OemToChar, which doesn't validate the buffer size:

char buff[MAX_PATH];
OemToChar(buff, input);  // If strlen(input) > MAX_PATH, this call leads to buffer overrun

The following code example avoids this warning by using the recommended alternative OemToCharBuff, which takes in the destination buffer size and limits the copy appropriately:

char buff[MAX_PATH];
OemToCharBuff(buff, input, MAX_PATH);