This will cause an invalid read, if the buffer doesn't contain an LF character. Assuming the buffer is guaranteed to be null terminated, checking for `p[i] == 0` would be more robust and I don't think the extra iteration will cause any performance issues.