The check for `(str[i] & 0b11000000) == 0b10000000` should follow the check for `i < length_of_s`; otherwise, it'll be possible for the former to run off the end of the string and attempt an invalid access, since it currently runs before the length check. Also, I'd feel better if the `str[i]` were cast to an unsigned char.