From 297a9b4b79e76751cf4a1cfc3c333995073b37a8 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Tue, 19 Jul 2022 07:37:59 -0500 Subject: [PATCH] Fix off by one error and add test case. --- tests/diff.test | 6 ++++++ toys/pending/diff.c | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/diff.test b/tests/diff.test index 8a1f99f4..bbef9d32 100644 --- a/tests/diff.test +++ b/tests/diff.test @@ -54,3 +54,9 @@ testcmd "fifos" "-u -L fifo1 -L fifo2 fifo1 fifo2" '--- fifo1 -2 +3 ' "" "" + +seq 1 100000 > one +seq 1 4 100000 > two +testcmd 'big hunk' '-u --label nope --label nope one two' \ + "$(echo -e '--- nope\n+++ nope\n@@ -1,100000 +1,25000 @@'; for((i=1;i<=100000;i++)); do (((i-1)&3)) && echo "-$i" || echo " $i"; done)\n" '' '' +rm one two diff --git a/toys/pending/diff.c b/toys/pending/diff.c index 6d63bd59..0ea8fc39 100644 --- a/toys/pending/diff.c +++ b/toys/pending/diff.c @@ -529,7 +529,7 @@ char *quote_filename(char *filename) if (quote) t[len++] = '"'; t[len] = 0; - return --t; + return t-quote; } // construct the new string -- 2.39.2