This isn't the right place for handling a BOM - this function is for converting a sequence of UTF-16 codeunits to native, it assumes they are already in the correct byte-order with no BOM... If this function is needed in a context where a BOM might be present, the decoding of the input needs to happen (to the point of getting a correct sequence of UTF-16 codeunits) before this is called. (From the point of view of this function, 0xFEFF and 0xFFFE are perfectly valid - mapping to the 'undefined' char).