# HG changeset patch # User Paul Boddie # Date 1709594115 -3600 # Node ID e0f251ba3681bbb2c0f589bb15cbcb4e8ceb71f0 # Parent 05541dabc5ad72e4afb759521f516d693304fb43 Fixed end-of-file handling at the end of the selected region. diff -r 05541dabc5ad -r e0f251ba3681 test_files/programs/clip.c --- a/test_files/programs/clip.c Mon Mar 04 22:32:42 2024 +0100 +++ b/test_files/programs/clip.c Tue Mar 05 00:15:15 2024 +0100 @@ -148,13 +148,25 @@ while (lineno < startline + numlines) { + /* Read a line, updating the current line number. */ + if (!readline(file, &lineno, &start, &end)) { + /* If the last line was passed, an empty line is an acceptable end-of-file + condition. */ + + if (lineno >= startline + numlines) + break; + + /* Otherwise, indicate that end-of-file occurred. */ + _fprintf(output, "EOF error at line %d.\n", lineno); client_flush(output); return 1; } + /* Emit line content while within the desired range of lines. */ + if ((lineno >= startline) && (lineno < startline + numlines)) client_write(output, start, end - start); }