diff mbox series

grep: simplify is_empty_line

Message ID pull.1418.git.git.1672333122193.gitgitgadget@gmail.com (mailing list archive)
State Superseded
Headers show
Series grep: simplify is_empty_line | expand

Commit Message

Seija Kijin Dec. 29, 2022, 4:58 p.m. UTC
From: Seija Kijin <doremylover123@gmail.com>

Signed-off-by: Seija Kijin <doremylover123@gmail.com>
---
    grep: simplify is_empty_line
    
    Signed-off-by: Seija Kijin doremylover123@gmail.com

Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1418%2FAtariDreams%2FisEmpty-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1418/AtariDreams/isEmpty-v1
Pull-Request: https://github.com/git/git/pull/1418

 grep.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)


base-commit: 6bae53b138a1f38d8887f6b46d17661357a1468b

Comments

Eric Sunshine Dec. 29, 2022, 5:06 p.m. UTC | #1
On Thu, Dec 29, 2022 at 12:00 PM Rose via GitGitGadget
<gitgitgadget@gmail.com> wrote:
> diff --git a/grep.c b/grep.c
> @@ -1483,9 +1483,10 @@ static int fill_textconv_grep(struct repository *r,
>  static int is_empty_line(const char *bol, const char *eol)
>  {
> -       while (bol < eol && isspace(*bol))
> -               bol++;
> -       return bol == eol;
> +       while (bol < eol)
> +               if (!isspace(*bol))
> +                       return 0;
> +       return 1;
>  }

The rewritten code appears to be quite broken. It never increments `bol`.
diff mbox series

Patch

diff --git a/grep.c b/grep.c
index 06eed694936..f29f4dd9e08 100644
--- a/grep.c
+++ b/grep.c
@@ -1483,9 +1483,10 @@  static int fill_textconv_grep(struct repository *r,
 
 static int is_empty_line(const char *bol, const char *eol)
 {
-	while (bol < eol && isspace(*bol))
-		bol++;
-	return bol == eol;
+	while (bol < eol)
+		if (!isspace(*bol))
+			return 0;
+	return 1;
 }
 
 static int grep_source_1(struct grep_opt *opt, struct grep_source *gs, int collect_hits)