...
Noncompliant Code Example (setlocale()
)
In this noncompliant code example, the function utf8_to_ucs()
attempts to convert a sequence of UTF-8 characters to the Universal Character Set (UCS). It first invokes setlocale()
to set the global locale to
but does not check for failure. The "
en_US.UTF-8"setlocale()
function will fail by returning a null pointer, for example, when the locale is not installed. ( The function may fail for other reasons as well, such as the lack of resources.) Depending on the sequence of characters pointed to by utf8
, the subsequent call to mbstowcs()
may fail or result in the function storing an unexpected sequence of wide characters in the supplied buffer ucs
.
...