If the first line is 18 characters followed by '\n', you've set first_line_len to 19, which is greater than MAX_LEADING; so you now copy MAX_LEADING+1 bytes, i.e. 19 bytes, which includes the '\n'; I don't think you wanted to do that.