It'd be cheaper to use <code> last_nl + last_line_len - MAX_TRAILING </code> instead of calling strlen yet again (on a string which is, apparently, somewhat long).