Use strchrnul() instead of strchr() plus manual workaround