atm you're returning -1 from SizeOfUtf8Char() which is incorrect here.  Perhaps just return 0 on error from that function?