rev: correct output for long input lines

The input buffer is initialised to a reasonable size and extended
if necessary.  When this happened the offset into the buffer wasn't
reset to zero so subsequent lines were appended to the long line.

Fix this and add some tests.

function                                             old     new   delta
rev_main                                             377     368      -9
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-9)               Total: -9 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Ron Yorston authored and Denys Vlasenko committed 2021-08-22 00:08:18 +02:00
1 parent 62d5a1e56f
commit 4357569fdc
2 files changed
+47

No files matched your search

+1
View File
@@ -109,6 +109,7 @@ int rev_main(int argc UNUSED_PARAM, char **argv)
strrev(buf, strlen(buf));
#endif
fputs_stdout(buf);
pos = 0;
}
fclose(fp);
} while (*argv);